Sunday, August 3, 2008

How To Change User's Default Shell

Changing specific shell type for linux users can be done in several ways using linux terminal commands. When you examine the file /etc/passwd linux file, the default shell type can easily be determined by looking at the last field of the line.

For example, if we wish to view john's default shell account type, simply

# cat /etc/passwd | grep john

A similar result as shown below

john:x:501:501::/home/john:/sbin/nologin

As you can see, the default shell type for user john has been declared as /sbin/nologin

Alternatively, to check for default user's shell type, simply

# finger john

A similar screen output

Login: john                          Name: (null)
Directory: /home/john                      Shell: /sbin/nologin
Never logged in.
No mail.
No Plan.
Change User's Default Linux Shell Type

To change john's default linux shell type from /sbin/nologin to /bin/bash shell type, simply user chsh. Linux command chsh, short for change shell, is used to change user's login shell. To use, simply

# chsh john

New shell [/sbin/nologin]: /bin/bash

Verify New User's Linux Shell Type

# finger john

Login: john                          Name: (null)
Directory: /home/john                      Shell: /bin/bash
Never logged in.
No mail.
No Plan.

As you can see, the linux shell type was permanently changed from /sbin/nologin to /bin/bash using chsh linux command.

Change Default User Login Shell Permanently

To change the default linux shell type every time a new user is created, simply backup and modify linux file /etc/default/useradd . Inside /etc/default/useradd, the default linux shell is explicitly defined. You can change that to suit your needs.

# cat /etc/default/useradd

GROUP=100
HOME=/home
INACTIVE=-1
EXPIRE=
SHELL=/bin/bash
SKEL=/etc/skel
CREATE_MAIL_SPOOL=yes

From the above /etc/default/useradd default user details, /bin/bash is the default linux login shell. Basically, this means every time a new user is created would inherit a default login shell of /bin/bash.

Display Linux Shell Types

To display all the available linux login shells, simply

# cat /etc/shells

The above command displays all the available linux login shells from your linux box. You can modify this to suit your setup needs.

All is done

0 comments:

Sign up for PayPal and start accepting credit card payments instantly.
ILoveTux - howtos and news | About | Contact | TOS | Policy