Print
Category: Computing
Hits: 2719

With a few custom configuration settings, and creative use, ssh can make it very easy to manage multiple computers.

Keys can eliminate the need to enter passwords every time you connect between two specific computers.

To create a public/private key pair:

ssh-keygen -t rsa

Use the default file and no passphase to save future typing. Copy the public key to the server's file:

.ssh/authorized_keys

Then to create quick logins:

make a shell file called ssh-to with

#!/bin/sh
ssh `basename $0` $*

Or, to support non-default ports:

#!/bin/bash

# get the host to ssh to
host="$(basename $0)"
port="22"
# check for a port number after :
ext=${host#*:}

# ext will match the host name if there's no port
if [ "$ext" == "$host" ] ; then
   # no special port requested
   ssh $host -X $*
else
   # set the port to what is after : and remove :port from host name
   port=$ext
   host=${host%:$ext}
   ssh $host -X -p $port $*
fi

Then link to this shell file with the network name of the target computer. Example,

ln -s ssh-to myserver.domain.com

Now you will be able to connect just by entering the computer's name on the command line.


To remove a known host key when there is a change such as the host's IP address:

ssh-keygen -R host.example.com

To support multiple hosts at one target IP address (on different ports) add to the ssh_config file separate Host sections like:

Host server1 server1.domain.com
     Hostname server1.domain.com
     HostKeyAlias server1
     Port 2202
     User bob
    CheckHostIP no