I have had a slightly annoying (but not fatal...yet) encounter with bash when I change /etc/passwd. I just changed one persons home directory, and now, wehn I log in as any user other than root in SSH, I get -bash-2.05b$ rather than the normal [user@server dir]$
I even tried undoing the changes in /etc/passwd with no avail. How can this be fixed?
Thanks in advance!
is it advisable to edit the /etc/passwd directly? if one has to change a user's password and home directory, login shell, doesn't one use another admin tool, like passwd and usermod, respectively?
You can edit the passwd file directly and it seems that this is more a profile problem check your /etc/profile seems like this new user is not picking its profile up try 'source /etc/profile' and see if you get the right prompt then.
I think I have figured out the problem...but I don't know wht it wasn't working last time I went back to the users original home. It needs all the .bash_* in the old home directory, including the users bash profile...but what gets me the most is it affected other users when the user didn'thave these files.
There are two sets of profiles and environment setup scripts that are run when a user logs in. When a user first logs in the global profile is run and the environment is setup. (/etc/profile) and then the user's profile is run. The user's profile takes precedence over the global profile.
You may be interested in the following files:
/etc/profile - processed first
/etc/bash.bashrc - called by /etc/profile
$HOME/.bash_profile - called next - should call $HOME/.bashrc
$HOME/.profile - called if no .bash_profile.
I believe I have the order correct however I am not 100% sure.
Generally not a good idea to edit the global ones unless you need to.
Without any of the above you will not have environment variables. ie no PATH and therefore you would have to type the full path to the command etc
will show you environment variables.
/etc/skel/* - these are used to setup a new account. Can also copy them to your home directory if you have deleted the old ones. Make sure you change the ownership of the files after copying.
Generally speaking it is not a good idea to edit the passwd, group and shadow file with vi in case someone else is also editing it. It is better practice to use useradd etc, groupadd etc and passwd.
If you are the only user on a box you can generally get away with it if you know what you are doing but it is not best practice.