14

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?

1

5 Answers 5

16

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
1
  • 2
    Best answer as of 2019. This answer needs more upvotes!
    – geekQ
    Dec 12, 2019 at 12:56
7

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
2
  • Is that alias really correct? Check your quotes.
    – user
    Sep 25, 2013 at 13:45
  • I think I'll go with this solution thanks!
    – brngp
    Sep 26, 2013 at 20:13
5

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

3
  • 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. Sep 25, 2013 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, 2013 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, 2013 at 22:05
3
sudo usermod -s /bin/zsh yourusername
0

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.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .