LinuxQuestions.org
Latest LQ Deal: Latest LQ Deals
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 11-28-2016, 12:45 PM   #1
atjurhs
Member
 
Registered: Aug 2012
Posts: 311

Rep: Reputation: Disabled
how do I treat a special character in my password as not


hi guys,

i'll start by prefacing my question that it is specific to an OSX version of bash if that makes any difference or not I don't know.

from the command line in an OSX terminal i want to issue a command that requires a sudo password, and lets say my sudo password is "abc&123"

sudo options command

gets me back a line with a little key on the far right side prompting me to enter my password. when i do it doesn't read my full password as abc&123 it splits my password at the & and then it doesn't accept the sudo command.

if i change my password to "abcand123" the sudo command works just fine and the command is executed

question: how can i tell osx to ignore the & character as a "special character" when it's part of my password. i know the easy fix is to just use "abcand123" password, but to help prevent hacking, I'd like to keep my password as complicated as possible and use "special characters" in it.

btw, I have tried to google this but I can't seem to find an answer there.

thanks!

Todd

Last edited by atjurhs; 11-28-2016 at 12:46 PM.
 
Old 11-28-2016, 12:47 PM   #2
szboardstretcher
Senior Member
 
Registered: Aug 2006
Location: Detroit, MI
Distribution: GNU/Linux systemd
Posts: 4,278

Rep: Reputation: 1694Reputation: 1694Reputation: 1694Reputation: 1694Reputation: 1694Reputation: 1694Reputation: 1694Reputation: 1694Reputation: 1694Reputation: 1694Reputation: 1694
Well, it all depends on how you are feeding it/redirecting it,.. but a possibliity is to escape the & with a slash \:

Code:
abc\&123
Storing passwords in scripts and commands like this is a terrible and insecure idea though. Just FYI.
 
Old 11-28-2016, 12:49 PM   #3
Disillusionist
Senior Member
 
Registered: Aug 2004
Location: England
Distribution: Ubuntu
Posts: 1,039

Rep: Reputation: 98
I think to OP is saying they type "sudo command" and get prompted for the password but it is not accepting the password

---------------------
Just tested on my Mac and it doesn't seem to have an issue with the & symbol for me

atjurhs if you can provide more information about what you are trying to do, I can perform a more specific test

Last edited by Disillusionist; 11-28-2016 at 01:00 PM.
 
Old 11-28-2016, 01:09 PM   #4
rtmistler
Moderator
 
Registered: Mar 2011
Location: USA
Distribution: MINT Debian, Angstrom, SUSE, Ubuntu, Debian
Posts: 9,882
Blog Entries: 13

Rep: Reputation: 4930Reputation: 4930Reputation: 4930Reputation: 4930Reputation: 4930Reputation: 4930Reputation: 4930Reputation: 4930Reputation: 4930Reputation: 4930Reputation: 4930
I think whichever the case may be, szboardstretcher at least has it correct in pointing out that some form of escape needs to be used. Either the backslash, putting the password within quotes, single or double. It depends what the OSX accepts for escape characters, likely the backslash or at least this is what a google search tells me.
 
Old 11-28-2016, 03:39 PM   #5
jefro
Moderator
 
Registered: Mar 2008
Posts: 21,981

Rep: Reputation: 3625Reputation: 3625Reputation: 3625Reputation: 3625Reputation: 3625Reputation: 3625Reputation: 3625Reputation: 3625Reputation: 3625Reputation: 3625Reputation: 3625
Wonder how it originally accepted the password?

Some oddity of languages or how OSX works? https://discussions.apple.com/thread/1641119?tstart=0
 
Old 11-28-2016, 03:45 PM   #6
szboardstretcher
Senior Member
 
Registered: Aug 2006
Location: Detroit, MI
Distribution: GNU/Linux systemd
Posts: 4,278

Rep: Reputation: 1694Reputation: 1694Reputation: 1694Reputation: 1694Reputation: 1694Reputation: 1694Reputation: 1694Reputation: 1694Reputation: 1694Reputation: 1694Reputation: 1694
That's from 8 years ago. Is this really, honestly, still a bug/problem in Apple? Amazing!

They should take a page from Unix where this was figured out in the 1970s. Almost 45 years ago.
 
Old 11-28-2016, 03:59 PM   #7
sneakyimp
Senior Member
 
Registered: Dec 2004
Posts: 1,056

Rep: Reputation: 78
I wonder if the command you are running might be a poorly-written shell script which tries to feed your sudo password to some other script without quoting or escaping the password, thereby creating a broken command somewhere in its guts.

For example, the mysql command lets you specify a password on the command line when calling a command. This is not recommended if you are typing commands in a terminal because the password might end up in your .bash_history file, which stores all the commands you enter. However, I recently wrote a script that prompts the user for their database password and then formulates mysql commands using that password. My script is "poorly written" in that it suffers from the very problem I'm trying to describe. I.e., assuming your password is abc&123 then my script constructs a mysql command that looks something like this:
Code:
mysql -u root -p abc&123 db_name < db_file.sql
If I enter a password that contains an ampersand, then that ampersand might actually get interpreted by the command line as a BASH operator that says "run this process in the background" or something like that. I'm not sure at all, but the command would be broken into these two commands
Code:
mysql -u root -p abc &
123 db_name < db_file.sql
The first command would be executed in the background and would be rejected by mysql as an improperly formulated command. The second would fail with a "123: command not found" or something.

I could be wrong.
 
Old 11-28-2016, 04:22 PM   #8
atjurhs
Member
 
Registered: Aug 2012
Posts: 311

Original Poster
Rep: Reputation: Disabled
Dillusionist, that is exactly what I'm saying

sneakyimp, as far as i can tell, that's exactly what is happening
 
Old 11-28-2016, 04:31 PM   #9
sneakyimp
Senior Member
 
Registered: Dec 2004
Posts: 1,056

Rep: Reputation: 78
Quote:
Originally Posted by atjurhs View Post
Dillusionist, that is exactly what I'm saying

sneakyimp, as far as i can tell, that's exactly what is happening
If you could edit the script you are executing, you could add quotes around the password any time it gets fed into some attempt to formulate a command. That might fix the ampersand problem but would not fix the problem if your password contains a quote in it. You could also change your password
 
Old 11-28-2016, 04:32 PM   #10
sneakyimp
Senior Member
 
Registered: Dec 2004
Posts: 1,056

Rep: Reputation: 78
If you didn't write the script, you should give a but report to whoever did.
 
Old 11-28-2016, 04:33 PM   #11
atjurhs
Member
 
Registered: Aug 2012
Posts: 311

Original Poster
Rep: Reputation: Disabled
next problem...

how do i modify my .bash file in osx?

in linux i would simple enter the command texedit .bash from my home directory

if i try open -e .bash from my home directory it says that file does not exist, if i try the same command with .bashrc i get the same answer does not exist.

when i try to ls .* it also does not list a .bash or .bashrc file

where else could my .bash file be located, or what else am i doing wrong?

i want to set up some aliases like:

up = 'cd ..'
ll = 'ls -alhf'

and others.

Last edited by atjurhs; 11-28-2016 at 04:37 PM.
 
Old 11-28-2016, 04:37 PM   #12
sneakyimp
Senior Member
 
Registered: Dec 2004
Posts: 1,056

Rep: Reputation: 78
My guess is that you are not actually running BASH on your OSX machine. Also curious why you are editing this file as it doesn't sound like that's where the problem lies.

Some searching yields:
Quote:
So turns out that on Mac OS X Snow Leopard as well as Mac OS X Lion, the file that's loaded is called .profile, not .bashrc.

What you want to do is create a file in ~/.profile and call it .profile (if it doesn't already exists).

Put whatever information you needed to load with each instance of bash there (Thanks, thepurplepixel).

A couple of side notes:

The period in front of the file marks it as invisible to Finder and the ls command by default. To list invisible files using the ls command from Terminal, use the -a as a parameter as such: ls -a
The ~ symbol stands for /Users/YourUserName where YourUserName is your username's shortname.

Edit: Chris Page notes (correctly) that whatever you place in a .profile file will apply to whatever shell you're using (i.e. zhs, bash, et cetera). If you want the contents to affect only the bash shell, place the contents in a .bash_profile file instead of a .profile file.
 
Old 11-28-2016, 05:19 PM   #13
atjurhs
Member
 
Registered: Aug 2012
Posts: 311

Original Poster
Rep: Reputation: Disabled
thanks sneakyimp!

i forgot to include the -a in my ls comand

actually that's one reason why (on my linux box at work) i have an alias ll = 'ls -alhf' and then i never type ls i just always type ll so i don't forget all the options...

well creating a .bash_profile or just a .profile in osx, osx does appear to apply the command when opening a new terminal, however i get lots of errors

note, it is a bash shell because the is a .bash_history file and a .bash_sessions directory


can someone reccommend an osx specific forum like linux questions, or is there a osx specific forum here, i haven't found one
 
Old 11-28-2016, 05:39 PM   #14
sneakyimp
Senior Member
 
Registered: Dec 2004
Posts: 1,056

Rep: Reputation: 78
After making changes to your .profile or .bashrc file you have to reload it somehow. This may answer both of your questions:
http://apple.stackexchange.com/quest...liases-to-work
 
Old 11-28-2016, 06:41 PM   #15
atjurhs
Member
 
Registered: Aug 2012
Posts: 311

Original Poster
Rep: Reputation: Disabled
thanks snaeky!

i found the answer on how to the modify your osx "bash shell"
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
block special and character special files s_shenbaga Linux - Newbie 4 06-23-2015 02:16 AM
sed command to replace special character in special line rubylu Linux - Newbie 3 04-09-2015 01:45 PM
Find and Replace character/special character from the file MyRelam Red Hat 8 05-21-2012 12:52 AM
i need help with a special character Hone101 Linux - Newbie 1 05-03-2003 07:21 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 04:04 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration