Configure SSH password-less login for Ubuntu and CentOS

Source: Internet
Author: User
1. Run the following command to install sshUbuntu: $ sudoapt-getinstallopenssh-serveropenssh-client $ sudoapt-getinstallopenssh-serveropenssh-clientCentOS: $ sudoyuminstallopenssh-serveropenssh-

1. Install ssh

Run the following command in Ubuntu:

  1. $ Sudo apt-get install openssh-server openssh-client
$sudo apt-get install openssh-server openssh-client

 

CentOS command:

  1. $ Sudo yum install openssh-server openssh-client
$sudo yum install openssh-server openssh-client

 

Run the following command to start ssh:

  1. $ Sudo service sshd start
$sudo service sshd start

 

2. Configure SSH login without a password

The configuration in Ubuntu is as follows:

  1. $ Ssh-keygen-t dsa-p''
  2. Generating public/private dsa key pair.
  3. Enter file in which to save the key (/home/aaron/. ssh/id_dsa ):
  4. Created directory '/home/aaron/. ssh '.
  5. Your identification has been saved in/home/aaron/. ssh/id_dsa.
  6. Your public key has been saved in/home/aaron/. ssh/id_dsa.pub.
  7. The key fingerprint is:
  8. Bd: 2c: ed: AB: 6d: a9: b2: 45: 88: 32: 08: 5a: d2: d9: ad: cc aaron @ ubuntu
  9. The key's randomart image is:
  10. + -- [DSA 1024] ---- +
  11. |
  12. |. O. |
  13. | O +... |
  14. | O + o... |
  15. | O E. S. |
  16. | O. o. |
  17. | O +. |
  18. |... + O |
  19. |. Oo ++. |
  20. + ----------------- +
$ ssh-keygen -t dsa -P ''Generating public/private dsa key pair.Enter file in which to save the key (/home/aaron/.ssh/id_dsa):Created directory '/home/aaron/.ssh'.Your identification has been saved in /home/aaron/.ssh/id_dsa.Your public key has been saved in /home/aaron/.ssh/id_dsa.pub.The key fingerprint is:bd:2c:ed:ab:6d:a9:b2:45:88:32:08:5a:d2:d9:ad:cc aaron@ubuntuThe key's randomart image is:+--[ DSA 1024]----+|                 || . o .           ||o + . .          ||o+ o o . .       ||o o E . S .      ||   o   . o .     ||        o +.     ||      .. +o      ||      .oo++.     |+-----------------+

(Note: After you press enter ~ Two files are generated under/. ssh/: id_rsa and id_rsa.pub. These two files are paired .)

 

Add the content in id_dsa.pub to the public key file for authentication. The command is as follows:

  1. $ Cat id_dsa.pub> authorized_keys
$ cat id_dsa.pub >> authorized_keys

You can copy the generated authorized_keys to another machine.

  1. $ Cat ~ /. Ssh/authorized_keys | \
  2. Ssh aarron@192.168.1.108 "cat-> ~ /. Ssh/authorized_keys"
$ cat  ~/.ssh/authorized_keys | \ssh aarron@192.168.1.108 "cat - >> ~/.ssh/authorized_keys"

Log on to localhost. Enter the command: ssh localhost on the terminal. (Note: After you remotely log on to another machine through ssh, You need to execute the exit command to control the local host again .) Run the exit command. Enter the command: exit

 

If a problem occurs during the configuration process, the general problem is that the file permission settings are incorrect. Set the access permissions of. ssh and authorized_keys to 755 600, respectively. The command is as follows:

  1. $ Chmod 755 ~ /. Ssh
  2. $ Chmod 600 ~ /. Ssh/authorized_keys
$ chmod 755 ~/.ssh$ chmod 600 ~/.ssh/authorized_keys

The above is an example of the Ubuntu platform. The following describes how to configure it on the CentOS platform.

 

First, set the/etc/ssh/sshd_config file. Remove the comments of the following three lines in the/etc/ssh/sshd_config file:

  1. $ Sudo vim/etc/ssh/sshd_config
  2. RSAAuthentication yes
  3. PubkeyAuthentication yes
  4. AuthorizedKeysFile. ssh/authorized_keys
$sudo vim /etc/ssh/sshd_configRSAAuthentication yesPubkeyAuthentication yesAuthorizedKeysFile      .ssh/authorized_keys

The remaining steps are the same as the configuration in Ubuntu.

Related reading:

The whole process of configuring SSH service under Ubuntu and the solution of http://www.linuxidc.com/Linux/2011-09/42775.htm

Install Git, SSH and Permission denied solutions in Ubuntu 12.04 http://www.linuxidc.com/Linux/2013-06/85336.htm

Ubuntu 12.10 OpenSSH offline Installation Method http://www.linuxidc.com/Linux/2013-04/82814.htm

Install or set http://www.linuxidc.com/Linux/2013-07/87368.htm in SSH under Ubuntu

For more information about CentOS, see the CentOS topic page http://www.linuxidc.com/topicnews.aspx? Tid = 14

For more information about Ubuntu, see Ubuntu special page http://www.linuxidc.com/topicnews.aspx? Tid = 2

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.