Skip to content

SSH Tips and Tricks

2009 June 25
tags: , ,
by Hardik Dalwadi

Many of you know that how to do password less login with SSH.
Here is simple way to do that. First of all, please generate authentication keys for ssh by using ssh-keygen command.

#ssh-keygen -t dsa

Above command will generate authentication keys for ssh in our home directory. For password less login we need ‘id_dsa.pub’ file. Now we have to transfer this key to our server where we have to enable public key authentication. ssh-copy-id is best friend to copy that key to our server’s ~.ssh/authorized_keys file.

#ssh-copy-id -i /root/.ssh/id_dsa.pub person@CREATIVEDESKDESK

After giving password it will copy those key to our server. That’s it, you have enable your password less login from your Linux
Laptop/Desktop to your server. Just ssh to our server to see the magic.

#ssh person@CREATIVEDESKDESK

If you want to know other way to do this, i will recomend to visit [1] befor going further.

[1] http://www.biostat.jhsph.edu/bit/nopassword.html

Now my magic will start from here. For example, one often needs to log in to servers CREATIVEDESK, red, green, blue.

1. create a simple script called ‘ssh-to-server’ and put it in
/usr/local/sbin:

      #! /bin/bash

     ssh `basename $0` $*

2. create symlinks with names of the servers:

      # cd /usr/local/sbin

     # chmod 0755 ssh-to-server

     # ln -s ssh-to-server CREATIVEDESK

     # ln -s ssh-to-server red

     # ln -s ssh-to-server green

     # ln -s ssh-to-server blue

Then (if your path includes /usr/local/sbin) one can simply ssh to ‘CREATIVEDESK’ server by typing ‘CREATIVEDESK’ (or run a command on the ‘CREATIVEDESK’ server by ‘CREATIVEDESK uptime’). If the servers need to be accessed by fully qualified domain name, symbolic link to the ssh-to-server script to the FQDN.

Examples,

1. Server’s uptime

#CREATIVEDESK uptime
 18:34:28 up 62 days, 22:49,  2 users,  load average: 0.12, 0.05, 0.01

2. Copy sinlge or multiple file with or without archive

Transfering Single file:

# cat foo | CREATIVEDESK cat > foo

Transfering Multiple files with archive in desire remote location:

#tar -c -f - bar | CREATIVEDESK "cd /tmp; tar -x -f -"

You can find lot SSH Tips and Tricks on the internet. I have a good reference for you.

That’s all for now…

One Response leave one →
  1. walvim permalink
    December 5, 2009

    f you are using a system without ssh client then you can use webbased ssh clients (a ssh client on a website) like electrica.
    (Also handy when behind a firewall only allowing http traffic)

Leave a Reply

Note: You can use basic XHTML in your comments. Your email address will never be published.

Subscribe to this comment feed via RSS

Ubuntu