I recently acquired a shell account on a NetBSD box, where the default shell that came with the account happened to be the zsh. I personally prefer bash and set out to change to it accordingly. This short guide will give some information about changing the default shell:
The /etc/passwd file contains user credentials separated by colons (:). The following is an example of a line found within /etc/passwd:
The above can be broken down as follows:
- Username: jdoe
- Encrypted password is signified by a *
- User ID (UID): 202
- Group ID (GID): 1
- Full name of the user: John Doe
- User home directory: /home/jdoe
- Default shell: ksh
As you can tell in the above example, the default shell is set to /usr/bin/ksh. There are a number of ways that this can be changed. The first thing to do is find out what available shells are present on your system. This can be accomplished by checking the /etc/shells file.
bash is already installed on this system and is available to choose. Checking the /etc/shells file will also list the absolute path. Another way to check if bash is installed is by running the which command: $ which bash If the application we are checking is installed, it will return to absolute path for it.
Now that we’ve determined that bash is installed, we can go ahead and change our default shell to it. The first option to do this is utilizing the usermod utility. This edits the user’s details within the /etc/passwd file. Utilizing the -s or –shell option will edit the user’s default shell. The following example will edit the /etc/passwd file and replace the default shell to bash, defining the path we saw earlier, for the user jdoe. The absolute path has to be defined for the shell:
$ usermod -s /usr/pkg/bin/bash jdoe
The next option is using the chsh utility – which is short for change shell – which works much the same way as the usermod utility and uses -s and –shell options:
$ chsh -s /usr/pkg/bin/bash jdoe
The last option you have is to manually edit the /etc/passwd file. You will need to have superuser permissions.
To verify that these changes have taken affect, you can look for the user within the /etc/passwd file and check what default shell is assigned. You can use grep to search for the username:
$ grep jdoe /etc/passwod jdoe:*:202:1:John Doe:/home/jdoe:/usr/pkg/bin/bash
As you can see, we have verified that the default shall has been changed for user jdoe.