I. Linux tips
5. Change user default login command
I needed to change the login command to execute a script of my own when a user logged in for the first time. At first, I changed the
.bashrc file to execute it from there, but it had some bothering disadvantages. So I decided to go lower and finally found what I was looking for by changing directly
This file contains a lot of useful information (such as encrypted password, users' login, user id (if 0, it's supposed to be root), group, login commands, home directory, etc...). It looks like this:
Each column of this file is separated by ':' and a line equals a row. So first is the login and last is the login command (I think you can guess pretty well what are the other fields). You can edit this file by hand if you want (even if I don't recommend it) or use commands which will do it for you (and avoid doing crap).
chsh is certainly the best I know for doing this. I'll show how to use it with
sudo chsh -s /bin/my_super_script the_user_i_want_to_modify
All login commands paths have to be absolute! Also, if you don't specify an user,
chsh will be executed for the current user (so
In this case, it's only if you create a new user.
useradd command has also a
-s option which allow to change the login command as well. Example:
useradd -s /bin/my_super_script the_user_i_want_to_create
The login command path still must be absolute!
If you want more information, don't hesitate to take a look at their manual.