Where do I change my shell?

If I wanted to use zsh, for instance, rather than bash, where would I make this change for the current user?

Answers:

Thank you for visiting the Q&A section on Magenaut. Please note that all the answers may not help you solve the issue immediately. So please treat them as advisements. If you found the post helpful (or not), leave a comment & I’ll get back to you as soon as possible.

Method 1

usermod -s /bin/zsh <username>

See man usermod for more options.

Method 2

Chris Browne’s answer works well if you don’t have access to the user and have root privileges.

If you want to change the default shell of your current user you can also use:

chsh -s /bin/ksh

More info

The login shell of a user is defined in a file (/etc/passwd on Debian). This files has an entry for each user with the info entered at creation.

rahmu:x:1000:1000:My Nameisrahmu,,,:/home/rahmu:/bin/bash
anotheruser:x:1001:1001:,,,:/home/anotheruser:/bin/ksh

The last column is the login shell. It will be forked by the login program if successful.

However it is highly recommended that you do not modify this file by hand. You should use chsh or usermod whenever possible.

Method 3

You can change your login shell with the chsh command. As man chsh notes, a normal user can only change the shell for their own account, while root can change the shell for all accounts.

/etc/shells contains the pathnames of valid login shells. This file is queried by chsh when it is invoked.

The instructions for using chsh vary according to your UNIX flavour:

Linux:

chsh -s <em>newshell</em>

Solaris:

chsh <em>newshell</em>

HP-UX

chsh <em>username newshell</em>

AIX

chsh

This will start an interactive session where you are prompted for the full path to your new shell.

Reference: http://kb.iu.edu/data/benf.html

Method 4

On systems where you don’t have sudo access or proper permission to use chsh (for example if you cannot add /bin/zsh to /etc/shell), then you can do it the old fashioned way:

$ mv ~/.bash_profile ~/.bash_profile.old
$ (echo :; echo exec /bin/zsh -il) > ~/.bash_profile
$ source ~/.bash_profile

This will replace the bash shell with a login zsh at login.

Method 5

I was trying to do this on a Synology device running DSM 5.1 with ash shell running. For some reason the chsh command was not available. I had to instead edit the file /etc/passwd, putting in the full path to the shell executable I instead wanted.


All methods was sourced from stackoverflow.com or stackexchange.com, is licensed under cc by-sa 2.5, cc by-sa 3.0 and cc by-sa 4.0

0 0 votes
Article Rating
Subscribe
Notify of
guest

0 Comments
Oldest
Newest Most Voted
Inline Feedbacks
View all comments
0
Would love your thoughts, please comment.x
()
x