Change Login Shell of Linux User
There are a couple of ways to change login shell of Linux user. We can change
the login shell while creating a new user account or for an existing user. If
creating a new user then use -s
or --shell
option in useradd command but
for an existing user chsh or usermod command.
Please run following 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 regular user otherwise disallow access to users with shells not included in this file. /etc/shells is a text file which contains the full pathnames 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
Please run following command to change the login shell of an existing user. 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 account,
# chsh -s /bin/bash
chsh command can also be used to view the list of valid login shells,
# chsh -l
Please provide any feedback using the comments below, and I invite you to check out following posts.