Howdy, Stranger!

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

Sign In with OpenID
Advertise on LowEndTalk.com

In this Discussion

Question...

Question...

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 chrisvps1.chriseaston.info or xxx.xxx.xxx.xxx; Is there a simple way of just having server 1 be able to connect to server 2 by just saying "ssh root@server2" instead of an IP or long hostname?

I might be missing something here; help?

Systems Administrator | IWFHosting

Comments expressed are solely my own opinion and not of that of the companies, unless stated.

Comments

  • MrAndroidMrAndroid Member
    edited July 2012

    Yes

    Add it to /etc/hosts

    xxx.xxx.xxx.xxx server2

    The Original Daniel.

  • netomxnetomx Member

    I thin you can put it on /etc/hosts

    Referral links: DigitalOcean referral link | Free 15GB with Copy | Get 500MB free with Dropbox | I sell domains with Google Apps, $0.50 p/ user
  • eastoncheastonch Member
    edited July 2012

    oh lol.

    I feel like such a fool now :']

    Systems Administrator | IWFHosting

    Comments expressed are solely my own opinion and not of that of the companies, unless stated.

  • 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.

    Systems Administrator | IWFHosting

    Comments expressed are solely my own opinion and not of that of the companies, unless stated.

  • u4iau4ia Member

    @eastonch said: ~/.bashrc

    exactly

  • 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?

    Systems Administrator | IWFHosting

    Comments expressed are solely my own opinion and not of that of the companies, unless stated.

  • 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?

    yes; 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/chriseaston.info/* 128mb:/home/backup/chriseaston.info/' and that would effectively backup my /chriseaston.info/ folder and xfer it to my other server? just by typing "rsync-chris"?

    Seems impossibruuu!

    Systems Administrator | IWFHosting

    Comments expressed are solely my own opinion and not of that of the companies, unless stated.

  • 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/chriseaston.info/* 128mb:/home/backup/chriseaston.info/' And maybe one more \ before the *

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

    Systems Administrator | IWFHosting

    Comments expressed are solely my own opinion and not of that of the companies, unless stated.

  • http://en.wikipedia.org/wiki/Escape_character#Programming_and_data_formats

    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.

    Systems Administrator | IWFHosting

    Comments expressed are solely my own opinion and not of that of the companies, unless stated.

  • u4iau4ia Member

    @eastonch said: Seems impossibruuu!

    Nothing is impossibruuu!

  • efballefball Member

    add chriseaston.info 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 chriseaston.info?

    Systems Administrator | IWFHosting

    Comments expressed are solely my own opinion and not of that of the companies, unless stated.

  • sleddogsleddog Member
    edited July 2012

    There's always Bash...

    #!/bin/bash
    # Filename: ssh2.sh
    if [ -z "$1" ]; then
        echo "Usage: ssh2 hostname [port]"
        exit
    fi
    SERV="$1.chriseaston.info"
    PORT="22"
    if [ -n "$2" ]; then
        PORT=$2
    fi
    ssh -p $PORT -l root -i /path/to/mykey $SERV
    exit 0

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

    Try it...

    [me@home] 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.