Page 1 of 2 12 LastLast
Results 1 to 10 of 11

Thread: Symbolic Link for SSH Remote Hostname

  1. #1
    Join Date
    Mar 2006
    Beans
    193
    Distro
    Ubuntu 10.04 Lucid Lynx

    [SOLVED] Symbolic Link for SSH Remote Hostname

    Hi,

    Is there a way to create a symbolic link to an off-site server, such that I don't have to type in user@xxx.yyy.zzz.aaa.bbb.ccc?

    Thanks!

    PS: I need to know how to do this on OSX, and on Ubuntu 10.04. I'm pretty sure it's the same command.
    Last edited by lazyrussian; January 25th, 2011 at 02:58 AM.

  2. #2
    Join Date
    Feb 2007
    Beans
    4,045
    Distro
    Ubuntu 9.10 Karmic Koala

    Re: Symbolic Link for SSH Remote Hostname

    If the IP is static, add an entry in /etc/hosts. E.g.
    Code:
    123.123.123.123 xxx.yyy.zzz.aaa.bbb.ccc shortname
    Then you can do
    Code:
    ssh user@shortname

    Another option is of course to make a shell function (or alias).
    Code:
    sshfoo() { ssh user@xxx.yyy.zzz.aaa.bbb.ccc "$@"; }
    Add it to the end of ~/.bashrc to make it permanent.

  3. #3
    Join Date
    Mar 2006
    Beans
    193
    Distro
    Ubuntu 10.04 Lucid Lynx

    Re: Symbolic Link for SSH Remote Hostname

    Thanks! Modifying /etc/hosts worked perfectly!

  4. #4
    Join Date
    Feb 2010
    Beans
    91

    Re: Symbolic Link for SSH Remote Hostname

    ssh has its own mechanism for this, you don't need to touch /etc/hosts. You can do something like in your local ssh_config

    Code:
    host shortcut
        hostkeyalias name_in_known_hosts_file
        hostname longame_or_ip_address
        port non_standard_port_number
    This tells ssh that hostname shortcut has a known_hosts keyname of hostkeyalias, a real ip address or DNS host name of longame_or_ip_address, and an ssh listen port number of non_standard_port_number. This entry would reduce the ssh login command from

    Code:
    ssh -p non_standard_port_number -o HostKeyAlias name_in_known_hosts_file \\
    user@longame_or_ip_address
    to
    Code:
    ssh user@shortcut
    The hostkeyalias and port entries are extremely useful if you are contacting a host via port forwarding through a gateway machine. man ssh_config for more.

  5. #5
    Join Date
    Mar 2006
    Beans
    193
    Distro
    Ubuntu 10.04 Lucid Lynx

    Re: Symbolic Link for SSH Remote Hostname

    Quote Originally Posted by talonmies View Post
    ssh has its own mechanism for this, you don't need to touch /etc/hosts. You can do something like in your local ssh_config

    Code:
    host shortcut
        hostkeyalias name_in_known_hosts_file
        hostname longame_or_ip_address
        port non_standard_port_number
    This tells ssh that hostname shortcut has a known_hosts keyname of hostkeyalias, a real ip address or DNS host name of longame_or_ip_address, and an ssh listen port number of non_standard_port_number. This entry would reduce the ssh login command from

    Code:
    ssh -p non_standard_port_number -o HostKeyAlias name_in_known_hosts_file \\
    user@longame_or_ip_address
    to
    Code:
    ssh user@shortcut
    The hostkeyalias and port entries are extremely useful if you are contacting a host via port forwarding through a gateway machine. man ssh_config for more.
    Thanks, I'll look into it later today!

  6. #6
    Join Date
    Jan 2006
    Beans
    Hidden!
    Distro
    Ubuntu 10.10 Maverick Meerkat

    Re: Symbolic Link for SSH Remote Hostname

    yeah, don't use hosts for "shortcuts" for ssh, if it's needed system and DNS is not an option for w/e reason, then use hosts. otherwise, use ssh_config.
    I am infallible, you should know that by now.
    "My favorite language is call STAR. It's extremely concise. It has exactly one verb '*', which does exactly what I want at the moment." --Larry Wall
    (02:15:31 PM) ***TimToady and snake oil go way back...
    42 lines of Perl - SHI - Home Site

  7. #7
    Join Date
    Mar 2006
    Beans
    193
    Distro
    Ubuntu 10.04 Lucid Lynx

    Re: Symbolic Link for SSH Remote Hostname

    So, why are you guys against editing /etc/hosts?

  8. #8
    Join Date
    Feb 2010
    Beans
    91

    Re: Symbolic Link for SSH Remote Hostname

    1. Because you wind up hard coding something that is potentially dynamic and might change in an important system file that directly effects TCP/IP behaviour. You can be left with really hard to diagnose network problems at some time in the future.
    2. Because it isn't always practical or possible for users to edit the hosts file, and if they did they would be propagating their personal customizations system and possibly network wide, if the host in question runs certain flavours of DHCP or caching DNS server.
    3. Because SSH already provides a secure, local user level mechanism which has no effect on other users or system/network wide TCP/IP behaviour specifically for the purpose you are asking about.

    Also, you mentioned OS X. Here is an interesting question: How many hosts files are there on a standard OS X installation? If the answer is more than one , which should you edit, and what happens when you reboot or install operating system upgrades? The answers to all three questions might surprise you.....

  9. #9
    Join Date
    Mar 2006
    Beans
    193
    Distro
    Ubuntu 10.04 Lucid Lynx

    Re: Symbolic Link for SSH Remote Hostname

    Quote Originally Posted by talonmies View Post
    1. Because you wind up hard coding something that is potentially dynamic and might change in an important system file that directly effects TCP/IP behaviour. You can be left with really hard to diagnose network problems at some time in the future.
    2. Because it isn't always practical or possible for users to edit the hosts file, and if they did they would be propagating their personal customizations system and possibly network wide, if the host in question runs certain flavours of DHCP or caching DNS server.
    3. Because SSH already provides a secure, local user level mechanism which has no effect on other users or system/network wide TCP/IP behaviour specifically for the purpose you are asking about.

    Also, you mentioned OS X. Here is an interesting question: How many hosts files are there on a standard OS X installation? If the answer is more than one , which should you edit, and what happens when you reboot or install operating system upgrades? The answers to all three questions might surprise you.....
    To my knowledge, there is only one hosts file. I edited it, and everything started working. Apparently, I had edited it in the past (2 years ago). In those 2 years, I forgot that that was the file I needed to edit, and that's what prompted my initial forum post.

    I am the only user on my computer, so I grant myself superuser access when I need it. I do see the problem of doing this for users who don't have SU access.

    Thanks for the explanation - much appreciated!

  10. #10
    Join Date
    Feb 2010
    Beans
    91

    Re: Symbolic Link for SSH Remote Hostname

    Quote Originally Posted by lazyrussian View Post
    To my knowledge, there is only one hosts file.
    Try again.....

    Code:
    MacBook-Air:~ avidday$ ls -l /etc/hosts
    -rw-r--r--  1 root  wheel  236 Sep 25 07:26 /etc/hosts
    MacBook-Air:~ avidday$ ls -l /private/etc/hosts
    -rw-r--r--  1 root  wheel  236 Sep 25 07:26 /private/etc/hosts

Page 1 of 2 12 LastLast

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •