I have to often do one of: ssh really-really-long-hostnameN where N is one of {10001-10099}

I would really like to be able to do: ssh myhostN

I have .bashrc entry: export myhost="really-really-long-hostname"

But then I have to do: ssh ${myhost}N

which is a huge improvement, but not quite what I wanted. Is there a way to do a substitution where I can do: ssh myhostN ?


For this I would write a function:

s() {
    ssh "really-really-long-hostname$1"

Then call it like so:

s 10037

Further reading:


Edit a file ~/.ssh/config and add entries like this for each host:

Host myhostN
    HostName    really-really-long-hostname100N

Set permissions to this file to 0600:

chmod 0600 ~/.ssh/config

Then you'll be able to use myhostN with ssh related commands (sftp, scp, etc.) instead of really-really-long-hostname100N.

  • Do I have to do this for each host, or can I do something with N to make it a one liner? – DDauS Oct 16 '16 at 10:29
  • @DDauS You have to do that for each host. You can automate the creation of the entries with a script. – Satō Katsura Oct 16 '16 at 14:37

I solved it like this: Edit your local /etc/hosts file. Add IP and name like this    my.google0     mygoogle1

..in the shell

ping mygoogle1

ssh my.google0

will work on local machine

Another way is using aliases.

Add to ~/.bashrc

alias ssh1='ssh -2 somehost.foo -l bar'

next time, when bash is executed you connect by typing ssh1.

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.