2

I want my local sshd to serve different shell, based on the host.

Example:

  • ssh user@hostname1 -> get's bash
  • ssh user@hostname2 -> get's fish

Is it possible, and if so, how can it be done?

  • Your examples do not match the question. E a.ples have two servers question has just the one – Mark Apr 13 at 1:07
2

I'm not able to find a way to accomplish what you're asking for directly with sshd and the options available in man sshd_config or man sshd.

Method #1 via ssh client

The first method that comes to mind is pretty straightforward. You can either do it directly with just ssh.

$ ssh -t user@someserver bash

-or-

$ ssh -t user@someserver dash

Examples

bash
$ ssh -t manny.bub.lan -l manny bash
$ ps | grep $$
31691 pts/0    00:00:00 bash
dash
$ ssh -t manny.bub.lan -l manny dash
$ ps | grep $$
31730 pts/0    00:00:00 dash
csh
$ ssh -t manny.bub.lan -l manny csh
manny:~% ps | grep $$
 1687 pts/0    00:00:00 csh
fish
$ ssh -t manny.bub.lan -l manny fish
Welcome to fish, the friendly interactive shell
manny@manny ~> ps | grep $$_
fish: $$ is not the pid. In fish, please use %self.
ps | grep $$
           ^
manny@manny ~> ps | grep %self
 4218 pts/0    00:00:00 fish

Method #2 via alias

You could leverage the above method in #1, and build aliases like these:

$ alias sshmanny1="ssh -t manny@manny-rei210-2.bub.lan bash"
$ alias sshmanny1="ssh -t manny@manny-rei210-2.bub.lan fish"

Then use them like so:

$ sshmanny1
manny@manny:~$ exit
exit
Shared connection to manny.bub.lan closed.


$ sshmanny2
Welcome to fish, the friendly interactive shell
manny@manny ~> exit
Shared connection to manny.bub.lan closed.

Method #3 ~/.ssh/config

The third method I was able to find would build configurations that can do this on the client side of your SSH connection, instead of on the server via SSHD.

$ cat ~/.ssh/config
Host manny1
    HostName manny.bub.lan
    RemoteCommand bash
    RequestTTY force
    User manny

Host manny2
    HostName manny.bub.lan
    RemoteCommand fish
    RequestTTY force
    User manny 

Now when you want to connect you'd do so like this:

$ ssh manny1
manny@manny:~$ exit
exit
Shared connection to manny.bub.lan closed.

$ ssh manny2
Welcome to fish, the friendly interactive shell
manny@manny ~> exit
Shared connection to manny.bub.lan closed.

References

You must log in to answer this question.

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