3

I have a hosting account which allows ssh login. There are several web sites on my hosting and each has its own ssh login, so I login as:-

ssh websitename@myhost.co.uk
ssh anothersite@myhost.co.uk
ssh yetanothersite@myhost.co.uk

What I hoped to do in ssh_config was something like:-

Host websitename anothersite yetanothersite
    Hostname myhost.co.uk
    User %h

But this doesn't work because the %h doesn't substitute in the User line.

Does anyone have any idea how I can achieve what I want, enter just the site name (well, it's actually just the first 8 letters of the site name) after ssh and get the result 'ssh sitename@myhost.co.uk'?

1
  • 4
    Might be simpler to alias the hosting server name (Host h Hostname myhost.co.uk and then do ssh websitename@h). Or write a shell function sshh() {ssh "$1"@myhost.co.uk;}
    – muru
    Feb 21 '17 at 14:19
5

You can use multiple Host directives, like that:

Host websitename anothersite yetanothersite
    Hostname myhost.co.uk

Host websitename
    User websitename 

Host anothersite
    User anothersite 

Host yetanothersite
    User yetanothersite

to achieve what you want.

That is not perfect, as you will have to duplicate the hostname/username several times, but AFAIK the best you can do with ssh_config.

Alternatively consider using a shell-level aliases, like that:

>alias websitename="ssh websitename@myhost.co.uk"
>websitename

or even a function:

>wssh() { ssh $1@myhost.co.uk }
>wssh anothersite

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.