I would like to start a remote session without typing the following command

ssh user@remoteserverip -t zsh

I know that I can change the host names in the ~/.ssh/config to simply use something like this:

ssh serveralias -t zsh

But I want to remove the -t zsh parameter.

Is there a way to achieve this without writing a function?


I don't think that is possible with ~/.ssh/config. The -t can be covered by adding a RequestTTY yes, but it doesn't seem you can specify the remote command in ~/.ssh/config.

However, with zsh, you could add a:

alias -g 'serveralias=serveralias -t zsh'

to your ~/.zshrc.

Or make a function like:

zssh() ssh "$@" -t zsh
  • Is that alias really correct? Check your quotes. – user Sep 25 '13 at 13:45
  • I think I'll go with this solution thanks! – brngp Sep 26 '13 at 20:13

For anyone arriving here years later, since 2017 it's possible to put everything in the config file:

Host host_1
    User root
    Port 22
    RequestTTY yes
    RemoteCommand zsh
  • Best answer as of 2019. This answer needs more upvotes! – geekQ Dec 12 '19 at 12:56

I concur with @Stephane that there isn't a way to do this using the ~/.ssh/config file. Another approach would be to use the ~/.ssh/authorized_keys file on the remote server. If you add a line like this:

command="exec zsh" ssh-dss ..... rest of key ....

Then you can just ssh as normal and you'll get a zsh on the remote server.


On server, ssh to remote.

$ ssh saml@greeneggs

On remote server, confirming we're in a zsh.

[saml@greeneggs]~% ps -eaf|grep $$
saml      1974  1973  1 10:34 pts/3    00:00:00 zsh
saml      2023  1974  0 10:34 pts/3    00:00:00 ps -eaf
saml      2024  1974  0 10:34 pts/3    00:00:00 grep --color=auto 1974

You can do more elaborate things using this file, see this Q&A, titled: ssh, start a specific shell, and run a command on the remote machine?.

  • command="exec zsh" is a bad idea: it makes it impossible to run ssh with an explicit command (so goodbye scp, rsync, …). unix.stackexchange.com/a/20739 shows how to do this decently. – Gilles 'SO- stop being evil' Sep 25 '13 at 22:09
  • I wasn't aware that it is possible to use the authorized_keys to execute commands. it is a pretty nice idea, but I'll use the solution from stephane because the issue pointed by Gilles. Thanks – brngp Sep 26 '13 at 20:15
  • @Gilles - yeah I found your solution and just showed the potential here, didn't want to just copy your solution here, that's why I referenced yours at the bottom of mine answer. – slm Sep 26 '13 at 22:05
sudo usermod -s /bin/zsh yourusername

You better change the system shell setting.

  1. Connect to server normally. ssh serveralias
  2. Execute chsh to change system shell
  3. Enter /bin/zsh to set it to zsh
  4. Reconnect with ssh serveralias and it'll show %

chsh [username] can be used to change other user's setting without reconnection.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.