0

My system admin manages a set of SSH configs for our remote servers, these configs are updated and pushed to my /etc/ssh/ folder regularly. However, host names in the managed ssh configs are too long to type (I'm lazy). Can I create host name aliases in my ~/.ssh/config? Note that this is not alias for HostName.

For example, my admin pushes configs to my /etc/ssh/ssh_config.d/ which look like this:

Host a.long.host.name
    HostName real-host-name.example.com
    ProxyCommand some proxy command
    ...

I want to give a.long.host.name a different, shorter name so I can type ssh foo instead of ssh a.long.host.name, I don't want to use shell alias because other commands like scp will need separate shell aliases.

I think ProxyCommand ssh -J localhost a.long.host.name would work, but localhost must be have sshd enabled, which I can't do.

2
  • I found an answer here which addressed this for me: unix.stackexchange.com/a/61666/503115 I hope that helps other travelers who might find themselves along this path. 🧙‍♂️
    – jg3
    Commented Jan 9 at 16:47
  • @jg3 Hmm.. Can you elaborate? That answer is helpful if the long host name and the short one are both in the same config file, in my case, the long host name is in a system config file, I need to add a short name in my own .ssh/config.
    – Gan Quan
    Commented Jan 10 at 17:14

2 Answers 2

0

"Host a.long.host.name" is an arbitrary name, it can be anything you like so long as it's not a duplicate or a reserved word etc. It is effectively an ssh config specific alias. User specific ssh configs will take precedence over system level configs in /etc/ssh/

2
  • 1
    The problem is I don't want to duplicated the managed configs in my personal ssh config file.
    – Gan Quan
    Commented Jul 22, 2022 at 18:37
  • I don't think there is a built in method to reference them, but only partially. One method is to create multiple ssh configs to separate work from personal. Something like: ssh -F ~/.ssh/workconf which could be an edited instance of /etc/ssh/config in which you could amend the server name aliases to be shorter to type. There is also an Include facility where you can reference external ssh config in your main one (ie Include workconf). This would mean you could ssh foo which comes from your work severs list without having to specify a file on the command line.
    – gsmitheidw
    Commented Jul 28, 2022 at 9:17
0

If you know the SSH port of the server (e.g., 22), you can do this with ProxyCommand, although it's kind of ugly and consumes extra CPU resources on the server:

Host <your-alias>
        ProxyCommand ssh -W localhost:22 <original-name>
New contributor
searchstar is a new contributor to this site. Take care in asking for clarification, commenting, and answering. Check out our Code of Conduct.

You must log in to answer this question.

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