How to use shorthand names for hostnames with ssh? You don’t always want to type in a complete host name when using ssh to remote hosts. Here is how to configure and use shorthand hostnames with ssh.
Configure shortened names for hosts for use with ssh
If you want to configure shortened names for your servers & hosts for use with SSH, follow the next steps:
Open up your
vi ~/.ssh/configCode language: Bash (bash)
and add the following:
Host your_short_name HostName server.on.the.web User user_to_userCode language: Bash (bash)
Save the file and exit (
Now you can use ‘
ssh your_short_name‘ instead of:
ssh -l username this-is-my-long-hostname.example.com.
Pretty neat, right?! :-)
want to manually install OpenSSH in Windows Server? Or Tunnel RDP through ssh?
This does not seem to work if the long form hostname relies of further configuration entries (with wildcards). e.g.:
Thank you for your comment Daniel. One entry can overrule another, yes. You can try to fiddle with CanonicalizeHostName and similar settings, see https://man.openbsd.org/ssh_config. I sometimes use
Hostname %h.my.domainin a
Hostsection and doing so allows me to ssh to server1 instead of server1.my.domain.
~/.ssh/config path does not exist anymore, please update your post!
OpenSSH still uses the configuration file
~/.ssh/config: https://man.openbsd.org/ssh_config#FILES. If it doesn’t exist, you can manually create the directory and file.