How do I set the shell that is used when a user SSHs to a server. For example I can't stand BASH and need to use ZSH, how do I make it so ZSH is loaded along with my profile (.zsh_profile
) when I ssh to the machine.
I dont want to have to pass a bunch of parameters with ssh either, can't I set the default shell?
Assuming you're running on Linux, you can use the
chsh
command.If you can't change your default shell,
ssh -t user@host 'zsh -l'
works.The
-t
flag forces a pseudo-tty allocation, and the-l
flag spawns a login shell.man chsh
changes shell, does not always workAlternatively, you can stick
exec /bin/zsh
in your bash login script.this will replace bash instance with your shell.Or you can do
ssh host "zsh -l"
Edit /etc/passwd (if you have the rights, or ask your system admin) to change your default shell.
I'm not sure how you can put your local
.zshrc
to remote server, (that's without permanently storing it there), this works for me to change my login shell on remote server.Since it's a shared account, I can use
zsh
only for myself with this method.Add this to your
~/.ssh/config
file in your local machine.There could be hackish way to accomplish what you are looking for, like below.
WARNING This comes with no guarantees and doesn't look 'wise', however I did managed to put my local file to server and source it in login shell using this.
How it works?
RemoteCommand
defines what needs to be run on remote side.LocalCommand
defines what needs to be run on local, which is used to copy your local file to remote server for sourcing it. Here is the catch, it happens only after 'successful' connection to remote host.Meaning:
sleep
sftp
to put your file to remote server, remote server wakes up fromsleep
and sources your scripts.It's super hackish, I'd like to know if there is a better way, too.
Update: This can be used instead of 'long' sleep time:
RemoteCommand zsh -l -c 'while [[ ! -f /tmp/somefile ]]; do sleep 0.05; done; source /tmp/somefile; zsh'
If you are using Windows:
ssh -t <username@servername> "powershell"
ssh -t <username@servername> "pwsh"
bash
(Git Bash or WSL), usessh -t <username@servername> "bash"
About the original question: change the shell opened by a SSH session, I don't think that it is configurable. You can change the shell used by the user on the system (
chsh
, or edit /etc/passwd), or even change the default shell of the machine, but not the SSH shell (I think SSH just opens a regular session with the user's parameters, including shell configuration).