Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

New on LowEndTalk? Please Register and read our Community Rules.


eastoncheastonch Member
edited July 2012 in General

Hey there;

I was looking into making SSH access slightly easier between some VPS's I have, and instead of having a hostname of or; Is there a simple way of just having server 1 be able to connect to server 2 by just saying "ssh [email protected]" instead of an IP or long hostname?

I might be missing something here; help?

Security Consultant


  • MrAndroidMrAndroid Member
    edited July 2012


    Add it to /etc/hosts server2

    The Original Daniel.

  • netomxnetomx Member, Moderator

    I thin you can put it on /etc/hosts

  • eastoncheastonch Member
    edited July 2012

    oh lol.

    I feel like such a fool now :']

    Security Consultant

  • u4iau4ia Member

    or just set up an alias in .bashrc

    alias ssh-server1='ssh -p 1234 [email protected]'

  • Oh, that's even better, as in, .bashrc in ~/.bashrc ?

    Since most of my servers are operating on random ports.

    Security Consultant

  • u4iau4ia Member

    @eastonch said: ~/.bashrc


  • Wow.

    So I can also use aliases for other things too, like I could setup one which does a certain long command like "io" could then do a "dd" test?

    Security Consultant

  • Use an SSH config file under ~/.ssh/

    Host *
    IdentitiesOnly yes
    Compression yes
    ServerAliveInterval 60
    # sub.domain.tld
    Host shortname
    Hostname sub.domain.tld
    Port 12345
    User username
    IdentityFile ~/.ssh/[email protected]

    'shortname' will appear in your SSH tab list.

    I use separate keys for various servers so it suits me to use 'IdentitiesOnly' but you can always omit it (including the 'IdentityFile' directive)

  • u4iau4ia Member
    edited July 2012

    @eastonch said: like "io" could then do a "dd" test?

    alias io='dd if=/dev/zero of=test bs=64k count=16k conv=fdatasync && rm test'

    alias has a lot of uses,for example i have an alias set for gst='git status', it's great for those often typed commands :)

  • effectively speaking @u4ia I could do
    alias rsync-chris='rsync --verbose --progress --compress --rsh='ssh -p xxx' /home/chris/http/hosts/* 128mb:/home/backup/'
    and that would effectively backup my / folder and xfer it to my other server? just by typing "rsync-chris"?

    Seems impossibruuu!

    Security Consultant

  • No, you need to escape some stuff

    I think it has to be
    alias rsync-chris='rsync --verbose --progress --compress --rsh=\'ssh -p xxx\' /home/chris/http/hosts/* 128mb:/home/backup/'
    And maybe one more \ before the *

    Thanked by 1u4ia
  • Why would you have to escape things? @gsrdgrdghd

    Security Consultant


    In this example bash would interpret the first ' (the one after --rsh=) as the matching ' that ends your alias.

  • Ooooh... Right, I see lol! Thanks for that mate.

    Security Consultant

  • u4iau4ia Member

    @eastonch said: Seems impossibruuu!

    Nothing is impossibruuu!

  • efballefball Member

    add to the search path in /etc/resolv.conf then you don't have to add individual hosts to the hosts file.

  • Oh, so I can just then do my128 since it's a subdomain of

    Security Consultant

  • sleddogsleddog Member
    edited July 2012

    There's always Bash...

    # Filename:
    if [ -z "$1" ]; then
        echo "Usage: ssh2 hostname [port]"
    if [ -n "$2" ]; then
    ssh -p $PORT -l root -i /path/to/mykey $SERV
    exit 0

    Set an alias...
    alias ssh2="/path/to/"

    Try it...

    [[email protected]] ssh2 vps1

    This way you don't have to keep modifying your hosts file or your aliases every time you get another vps :)

    Thanked by 1Victor
Sign In or Register to comment.