Monday, February 11, 2008

OSX Cmd: Change Your Shell

Mac OS X Leopard root shell default is, /bin/sh. My favourite is /bin/bash. Tried to change from /bin/sh to /bin/bash by editing /etc/passwd but it's not working. When su to root either via terminal or SSH remotely it's still used /etc/sh. Search for usermod command to change shell, as I always doing with others *NIX , but so far I couldn't find either usermod, useradd and userdel command on Mac OS X Leopard at all. Dang!!! Almost a week like a mad cat tried to figure out, at last found chsh command.

The chsh utility allows editing of the user database information associated with user or, by default, the current user. Type in below command to change your shell.

$ sudo chsh root

It will prompt you for password. Just put in your password.

Changing shell for root.
Password for root:

Then it will open up vi with below information. Move to 'Shell:/bin/sh line', and then press I to enter insert mode. Delete sh and replace it with bash. Then press , enter :wq and press to save file and quit. 

# Changing user information for root.
# Use "passwd" to change the password.
##
# Open Directory: /Local/Default
##
Login: root
Uid [#]: 0
Gid [# or name]: 0
Generated uid: FFFFEEEE-DDDD-CCCC-BBBB-AAAA00000000
Home directory: /var/root
Shell: /bin/sh
Full Name: System Administrator
Office Location:
Office Phone:
Home Phone:


Issue below command to check root default shell, it should return you /bin/bash.
 
$ sudo echo $SHELL
Password:
/bin/bash


4 comments:

Anonymous said...

What a life-saver! Best tip I've read all day.

Anonymous said...

Thanks,

This is has been bugging me for ages!
Now if only I could figure out where root's PS1 variable was being set (not .bashrc apparently)!!!

Anonymous said...

Thank you Sir. You are a gentleman and a scholar.

Anonymous said...

you need to set SUDO_PS1 if you want to change root's PS1 when using sudo.

Also, I don't know if it matters, but I feel safer using exec /bin/bash in the .profile instead of changing the shell since I don't know if it would mess up shell scripts in the system.