CentOS 6.5 ssh Password-free login configuration tutorial _linux

Source: Internet
Author: User
Tags chmod ssh centos

0. Notes

For the sake of illustration, let's say that there are two centos6.5 hosts installed on both A and B. The goal is to achieve a, B two hosts can be through SSH password-free login to the other host. As with the configuration process of different hosts, the configuration process of host A is described here.

Prior to the AB host to create a good password-free login to the user name, in the/etc/hosts file to increase the host name and IP.

Create a new User: Useradd LINUXIDC

Set Password: passwd linuxidc, enter the password you want, then su linuxidc switch User

Modify host Name: Vim/etc/sysconfig/network, join Hostname=master, logout system can be seen after the successful modification

To modify the Hosts file:

Vim/etc/hosts 
192.168.88.101 Master 
192.168.88.102 slave1

1. Environment setting

1.1 Shutdown Firewall (root permissions)

centos6.5 is very strict with network management and needs to shut down SELinux. To the/etc/selinux/config, change the selinux=enforcing to selinux=disabled. Root permission is required.

# su Root

Password:

$ vim/etc/selinux/config

Find SELinux and modify it to selinux=disable

1.2 Modifying the sshd profile (root permissions)

$ vim/etc/ssh/sshd_config

Find the following and remove the annotation "#"

Rsaauthentication Yes
pubkeyauthentication Yes
authorizedkeysfile. Ssh/authorized_keys

1.3 Restart the sshd service (root privileges)

$/sbin/service sshd Restart

2. Generate public and private keys on the computer

switch from root to user linuxidc to password-free logon to execute the command.

# ssh-keygen-t RSA

The default generates two files in the user LINUXIDC home directory (~/.ssh/):

Id_rsa: Private key

Id_rsa.pub: Public Key

3. Import the public key into the authentication file

3.1 Importing to the local machine

# cat ~/.ssh/id_rsa.pub >> ~/.ssh/authorized_keys

To complete this step, and then follow step 4 to modify the relevant file permissions, you can password-free login to this machine. You can enter the following command validation.

SSH localhost

If you can log on, the validation is successful.

3.2 Import to target host

3.2.1 On the native operation, to the target host

# SCP ~/.ssh/id_rsa.pub root@ target host IP or host name:/home/id_rsa.pub

Note that when transferring files to the target host, the root user is used, otherwise the permissions will not be denied. When you enter the target host password, OK is transmitted successfully.

3.2.2 Login to the target host, import the public key into the authentication file

Log on to the target host using the username LINUXIDC to be password-free. Then perform the following actions.

# cat/home/id_rsa.pub >> ~/.ssh/authorized_keys

Then follow step 4 to modify the relevant file permissions to complete the password-free login settings.

4. Change permissions on related files

# chmod ~/.ssh
# chmod ~/.ssh/authorized_keys

At this point, complete the password-free login settings.

5. Test

A host (Linuxidc@master), b Host (linuxidc@slave1). In a host, switch to LINUXIDC user, and perform the following command test:

SSH slave1

The above is a small set to introduce the CentOS 6.5 ssh password-free login configuration tutorial, I hope to help you, if you have any questions please give me a message, small series will promptly reply to everyone. Here also thank you very much for the cloud Habitat Community website support!

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.