Tuesday, August 31, 2010

Login To A Linux Server Without Password

Lets suppose that you need to run a command to update a module on multiple servers via ssh. Though using parallel ssh to save time, you would require to provide passwords on each server each time you will login. So the ultimate problem still remains their. Hows that if it would be possible that you run the command through parallel ssh and the operation went on smoothly without asking for any password..

Here how it would be-

1. Generate a pair of authentication keys. Give the command as below-

Note: even if is unsecured to work without password, do not enter it. Let it empty...


ssh-keygen -t rsa
You will get the output as below-
Generating public/private rsa key pair.
Enter file in which to save the key (/home/user1/.ssh/id_rsa):
Created directory '/home/user1/.ssh'.
Enter passphrase (empty for no passphrase):
Enter same passphrase again:
Your identification has been saved in /home/user1/.ssh/id_rsa.
Your public key has been saved in /home/user1/.ssh/id_rsa.pub.
The key fingerprint is:
31:df:a5:73:4a:2f:a6:6c:1c:32:a2:f2:b3:c5:a7:1f user1@computer1

The above command will generate id_rsa.pub key file in your /home/user1/.ssh folder

2. Now you need to copy this file to the ssh folder in the target server. Follow the command below-

cat .ssh/id_rsa.pub |ssh -p 99 root@72.52.93.20 'cat >> .ssh/authorized_keys'

where -

* -p is used to define port number of ssh.
* 99 is the port number.
* id_rsa.pub is the key file.
* root is the username to login with.
* 72.52.93.20 is the IP of the target server.
* .ssh/ is the ssh folder under root directory.
* authorized_keys is the id_rsa.pub file copied as authorized_keys on target server.

The CAT command will copy the id_rsa.pub file as authorized_keys file on the target server. You will be asked for the password while copy. 

If you wish you can restrict this file to be accessed by you only by setting the permission.

chmod 644 *

Now  you can try login to the server by typing its IP or name at your terminal and it should logged-in directly without asking for any password.

Parallel SSH

Well everybody knows what to do with ssh but what if you need to run a pair of commands on multiple servers ?

Login to each server through ssh and running that command will become a funny business. Isn't?

So here is the tool that can serve commands on multiple servers at the same time.


PARALLEL SSH

Installation

http://www.linux.com/archive/feature/151340

http://www.theether.org/pssh/


Operating PSSH

(in Ubuntu)

parallel-ssh -h hostfile.txt -l username -i -o /path_of_log_folder/folder command



where-

* -h indicates to the host file that contains the list of host servers.

* iplist.txt is the host file that contains the IP addresses (with port number for ssh) of the servers on which the command is to be run.

* -l indicates the next string as the username to be logged-in with.
* -i option in the displays the result of the execution on each server.
* -o specifies the path next to it where the output of the operation (log report)is saved in particular text files.

parallel-ssh -h iplist.txt -l root -i -o /home/robert/checklist/webmin rpm -q webmin

This command (rpm -q webmin) will check the version of webmin on all the servers listed in the iplist.txt file by logging-in with username as root and will generate the output of each server in particular files under folder webmin which is located at  /home/robert/checklist/

Working Out with Virtual Containers on Linux

Viewing List of running Containers on a system

Login to the base system via putty and type-

xm list

Starting UP a container

First go to the path of the container where it is located.

cd /etc/xen/auto

xm create (cont.name)



Shutting DOWN a container



xm shutdown (cont.name or id)





Forcefully Quitting The Container



xm destroy (cont.name or id)