1

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 ?

DDauS
  • 13

3 Answers3

1

For this I would write a function:

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

Then call it like so:

s 10037

Further reading:

Wildcard
  • 36,499
1

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.

Satō Katsura
  • 13,368
  • 2
  • 31
  • 50
0

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

216.58.211.14    my.google0
216.58.211.3     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.

Michael D.
  • 2,830