Change Login Shell of Linux User

This post will show you how to change the login shell of linux user. You can change the login shell while creating a new user account or for an existing user account. If you are creating a new user then simply use -s or --shell option in useradd command but if you like to change the login shell of an exiting user then use chsh or usermod command.

To create a new user named ftpuser with nologin shell,

# useradd -m -c "FTP User" -s /sbin/nologin ftpuser

Let's check if /sbin/nologin is present in /etc/shells file because there are programs (like ftp daemons) which consult this file to find out if a user is a normal user otherwise disallow access to users with shells not included in this file. /etc/shells is a text file which contains the full path names of valid login shells.

# cat /etc/shells

If nologin shell does not exist then just add /sbin/nologin to it,

echo "/sbin/nologin" >> /etc/shells

Now use the usermod command that modifies the system account files to reflect the changes that are specified on the command line. The -s or --shell option can be used to set the user's new shell,

# usermod -s /bin/bash ftpuser

Note: chsh command can also be used to change the login shell but chsh allows the user to change the login shell for his/her own account,

$ chsh -s /bin/bash

chsh command can also be used to view the list of valid login shells,

# chsh -l

Any feedback will be highly appreciated.

Suggested Posts,

This post appeared on the by Sumit Goel. Copyright © 2012 – and Sumit Goel. All rights reserved. Not to be reproduced for commercial purposes without written permission.

No comments:

Post a Comment

Be sure to check back again because I do make every effort to reply to your comments here.