How to change a user's shell?

QuestionsQuestions8 SkillsProUser Account ManagementSep, 29 2025
095

To change a user's shell in Linux, you can use the chsh (change shell) command or the usermod command. Here’s how to do it using both methods:

Method 1: Using chsh

  1. Change the Shell: You can change the shell for a specific user by running the following command:

    chsh -s /bin/bash username

    Replace username with the actual username of the user whose shell you want to change, and /bin/bash with the desired shell path.

  2. Example: To change the shell for the user joker to bash, you would run:

    chsh -s /bin/bash joker
  3. Verify the Change: You can verify the change by checking the /etc/passwd file:

    grep 'joker' /etc/passwd

Method 2: Using usermod

  1. Change the Shell: You can also use the usermod command to change the user's shell:

    sudo usermod -s /bin/bash username

    Again, replace username with the actual username and /bin/bash with the desired shell path.

  2. Example: To change the shell for the user joker to bash, you would run:

    sudo usermod -s /bin/bash joker
  3. Verify the Change: As before, verify the change by checking the /etc/passwd file:

    grep 'joker' /etc/passwd

Important Notes

  • Ensure that the shell you are changing to is listed in /etc/shells, as some systems restrict users to only those shells.
  • After changing the shell, the user may need to log out and log back in for the change to take effect.

Conclusion

Changing a user's shell can be done easily with either the chsh or usermod command. If you have any further questions or need assistance with specific commands, feel free to ask!

0 Comments

no data
Be the first to share your comment!