预计阅读本页时间:-
Installing bash as a Login Shell
Having installed bash and made sure it is working correctly, the next thing to do is to make it your login shell. This can be accomplished in two ways.
Individual users can use the chsh (change shell) command after they log in to their accounts. chsh asks for their password and displays a list of shells to choose from. Once a shell is chosen, chsh changes the appropriate entry in /etc/passwd. For security reasons, chsh will only allow you to change to a shell if it exists in the file /etc/shells (if /etc/shells doesn't exist, chsh asks for the pathname of the shell).
广告:个人专属 VPN,独立 IP,无限流量,多机房切换,还可以屏蔽广告和恶意软件,每月最低仅 5 美元
Another way to change the login shell is to edit the password file directly. On most systems, /etc/passwd will have lines of the form:
cam:pK1Z9BCJbzCrBNrkjRUdUiTtFOh/:501:100:Cameron Newham:/home/cam:/bin/bash
cc:kfDKDjfkeDJKJySFgJFWErrElpe/:502:100:Cheshire Cat:/home/cc:/bin/bash
As root you can just edit the last field of the lines in the password file to the pathname of whatever shell you choose.
If you don't have root access and chsh doesn't work, you can still make bash your login shell. The trick is to replace your current shell with bash by using exec from within one of the startup files for your current shell.
If your current shell is similar to sh (e.g., ksh), you have to add the line:
[ -f /pathname/bash ] && exec /pathname/bash --login
to your .profile, where pathname is the path to your bash executable.
You will also have to create an empty file called .bash_profile. The existence of this file prevents bash from reading your .profile and re-executing the exec—thus entering an infinite loop. Any initialization code that you need for bash can just be placed in .bash_profile.
If your current shell is similar to csh (e.g., tcsh) things are slightly easier. You just have to add the line:
if ( -f /pathname/bash ) exec /pathname/bash --login
to your .login, where pathname is the path to your bash executable.