Introduction
In this lab, you will learn how to use the chsh command to change the default shell for a user account in a Linux system. The chsh command allows you to set the shell program that is executed when you log in to your user account. You will learn how to verify the changed default shell and ensure that the new shell is properly configured.
This lab covers the essential steps for managing user shells in a Linux environment, which is an important aspect of user and permission management. The instructions provided in the lab are easy to follow and include practical examples to help you understand the usage of the chsh command.
Understand the chsh Command
In this step, we will learn about the chsh command, which is used to change the default shell for a user account in a Linux system.
The chsh command allows you to change the default shell, which is the program that is executed when you log in to your user account. The default shell is typically set to /bin/bash, but you can change it to any other shell installed on your system, such as /bin/zsh, /bin/fish, or /bin/tcsh.
To use the chsh command, simply run the following command in the terminal:
sudo chsh -s /bin/zsh labex
This command will change the default shell for the labex user to /bin/zsh.
Example output:
Changing shell for labex.
chsh: shell '/bin/zsh' does not exist
In this example, the shell /bin/zsh does not exist on the system, so the command will fail. Make sure to specify a valid shell that is installed on your system.
Once you have changed the default shell, you can verify the change by running the following command:
echo $SHELL
This will output the current shell that is being used by the user.
Example output:
/bin/bash
In this example, the default shell is still /bin/bash, so the change has not been applied yet. You may need to log out and log back in for the change to take effect.
Change the Default Shell Using chsh
In this step, we will learn how to change the default shell for a user account using the chsh command.
First, let's check the current default shell for the labex user:
sudo chsh -s /bin/bash labex
echo $SHELL
Example output:
/bin/bash
As you can see, the current default shell for the labex user is /bin/bash.
Now, let's change the default shell to /bin/zsh:
sudo chsh -s /bin/zsh labex
This command will change the default shell for the labex user to /bin/zsh.
To verify the change, let's check the shell again:
echo $SHELL
Example output:
/bin/zsh
The output now shows that the default shell has been changed to /bin/zsh.
Verify the Changed Default Shell
In this final step, we will verify that the default shell for the labex user has been changed to /bin/zsh.
First, let's check the current shell:
echo $SHELL
Example output:
/bin/zsh
As you can see, the default shell is now /bin/zsh, confirming that the change was successful.
You can also check the user's shell information in the /etc/passwd file:
sudo cat /etc/passwd | grep labex
Example output:
labex:x:1000:1000:labex,,,:/home/labex:/bin/zsh
The output shows that the shell for the labex user is set to /bin/zsh.
Finally, you can log out and log back in as the labex user to ensure that the new default shell is used.
Summary
In this lab, we learned about the chsh command, which is used to change the default shell for a user account in a Linux system. We first understood the purpose of the chsh command and how to use it to change the default shell. We then demonstrated how to change the default shell for the labex user from /bin/bash to /bin/zsh, and verified the change by checking the current shell being used. The lab provided practical examples and step-by-step instructions to help users effectively manage the default shell for their user accounts.



