.ssh/config to start remote session in zsh

26,536

Solution 1

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

Solution 2

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

Host host_1
    HostName 1.2.3.4
    User root
    Port 22
    RequestTTY yes
    RemoteCommand zsh

Solution 3

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.

Example

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?.

Solution 4

sudo usermod -s /bin/zsh yourusername
Share:
26,536

Related videos on Youtube

brngp
Author by

brngp

Updated on September 18, 2022

Comments

  • brngp
    brngp almost 2 years

    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?

  • Gilles 'SO- stop being evil'
    Gilles 'SO- stop being evil' almost 11 years
    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.
  • brngp
    brngp almost 11 years
    I think I'll go with this solution thanks!
  • brngp
    brngp almost 11 years
    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
  • slm
    slm almost 11 years
    @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.
  • Michael Eyal Sharon
    Michael Eyal Sharon over 4 years
    Best answer as of 2019. This answer needs more upvotes!