How do I change my default shell to bash if I don't have access to chsh nor /etc/passwd?
I'm working on a university remote Linux account, and the default shell is sadly csh
without tab completion. How can I change my account's default shell to bash
? chsh
is not available.
Solution 1:
You should probably try asking your sysadmins if they can change your default shell for you. If they can't or won't (as was the case when I was in college), the workaround I used was to add
# Exec bash if using an interactive shell.
if ($?prompt) then
setenv SHELL /path/to/bash
exec $SHELL
endif
to .cshrc
. (Make sure to replace /path/to/bash
with a real path, of course. This could even be a version of bash
that resides under your home directory, if the system-provided version is too out-of-date for your taste.) For efficiency, it's best to do this as early in the .cshrc
as feasible, so that you avoid additional .cshrc
processing that will become moot once bash
replaces the csh
process.
Solution 2:
You could simply connect with
ssh -t yourhost bash
to execute the Bash shell automatically when you log in.
From the comments below you can see the alternative
ssh -t yourhost exec bash
exec
will run a new process and exit the old one, so the csh
process will exit directly.
If append -l
at the end of the command as an argument to Bash, it will be treated as a login shell, but perhaps that is not needed.
Solution 3:
The best solution I found was one over on stackexchange. Here is the link stackexchange and here is the solution:
create a .profile file in your home dir and paste in the following, or add to the end of your .profile if you already have one.
case $- in
*i*)
# Interactive session. Try switching to bash.
if [ -z "$BASH" ]; then # do nothing if running under bash already
bash=$(command -v bash)
if [ -x "$bash" ]; then
export SHELL="$bash"
exec "$bash"
fi
fi
esac