SSH login without password
Contents |
Description
It is very useful to automate tasks for several hosts at the same time. Start and stop services, list directories, operations with files. We can do it remotely using ssh but we cannot automate because password is required in interactive mode. To avoid this problem we can use rsa public keys. In this article we are going to view how to configure remote access to other machines via ssh without password prompt.
Generate rsa public key in local machine
Generate the public rsa key with ssh-keygen command
[zoomer@oel6 ~]$ ssh-keygen -t rsa Generating public/private rsa key pair. Enter file in which to save the key (/home/zoomer/.ssh/id_rsa): Enter passphrase (empty for no passphrase): Enter same passphrase again: Your identification has been saved in /home/zoomer/.ssh/id_rsa. Your public key has been saved in /home/zoomer/.ssh/id_rsa.pub. The key fingerprint is: 20:d0:44:d5:b8:ae:6e:a8:3a:30:24:93:a1:4c:37:db zoomer@oel6.localdomain The key's randomart image is: +--[ RSA 2048]----+ | .+o..o | |.. +. . . | |+o. = .. | |=o . P.. | |o. . T | |o . | |.. . . | |. . o | |+o o. | +-----------------+
Now in $HOME/.ssh we have the public key for our host:
[zoomer@oel6 .ssh]$ cd $HOME/.ssh [zoomer@oel6 .ssh]$ ls -la total 16 drwx------. 2 zoomer zoomer 4096 nov 23 11:07 . drwx------. 28 zoomer zoomer 4096 nov 23 10:43 .. -rw-------. 1 zoomer zoomer 1675 nov 23 11:07 id_rsa -rw-r--r--. 1 zoomer zoomer 405 nov 23 11:07 id_rsa.pub [zoomer@oel6 .ssh]$ cat id_rsa.pub ssh-rsa AAAAB3NzaC1yc2EBCDABIwAAAQEAw/naiJmXw7GS1TEFr8PixmbkGslyPqWGCgAmEupUFUwn1I++gsjz2+sGuxcknQahPJCReJlOsu3Ik8NiFuQ+kR7XsXpHcp7HmBiHU2Hk+u8fRSE+kxN717a2joufy0mA6V3ST3xmS8frKZIA7OEHOKHyvnE6SluZWYTgSDMKxfm2VJPa59MP+k4d1yRAuiLLJE8dsfMCekZER8k0gHxtyeH14QZVTekrREDQismlFDChhaJarQ9Ii3E2mX2ZD355y7LDdJFhRmsE4kKTb+/UvzRl4zIQdnucULWv1mddM3ypmYzi6E00qxKU1v0RbJpbpVlC8SxtJFe0iDgyKrieuw== zoomer@oel6host.localdomain
Copy public key to target host authorized_keys file
Copy your public key file id_rsa.pub to the target host on $HOME/.ssh directory and include the text in the authorized_keys file
[zoomer@oel6 .ssh]$ cat id_rsa.pub >> $HOME/.ssh/authorized_keys
Access using ssh without password
Now we can access in a passwordless mode with ssh to the remote machine
[zoomer@oel6 ~]$ ssh localhost Last login: Fri Nov 23 11:12:45 2012 from localhost [zoomer@oel6 ~]$
Common problems
Be sure that permissions are set as bellow in both machines:
[zoomer@oel6 ] chmod 755 $HOME $HOME/.ssh [zoomer@oel6 ] chmod 600 $HOME/.ssh/authorized_keys
If you enjoyed this article, you might also like
- Configure date time settings on Linux
- Create oracle user for installations
- Creating partitions greater than 2TB in Linux
- Crontab examples
- Fedora 17 Installation
- Grep examples
- Install Apache Tomcat 7 on Linux
- Install Hadoop on Linux
- Install JRockit 64bits on Linux
- Iptables Linux Firewall Start and Stop
- Linux ls command
- Linux Mint 14 Installation
- Linux Reference Cards
- Mageia 2 Installation
- Mount new disks Oracle Enterprise Linux
- Oracle Enterprise Linux 6.3 Installation
- Rotating Logs on Linux
- Setup Chroot SFTP in Linux. Securing SFTP
- Shell execute commands using all files listed (xargs vs while statement)
- SSH login without password