Example of SSH key authentication configuration in Centos6

Source: Internet
Author: User
Tags base64 chmod ssh


Environment:
Local system: win8.1 64-bit
Server System: CentOS 5/6 x86_64

General process:

1. putty generates public key and private key
2. Distribute the public key to the linux server so that putty can use the key to link to the linux server.
3. Export the private key to the openssh private key format and distribute it to xshell

1. Use putty to generate public key and private key

1. Download putty
File Download
2. Generate a key
Run puttygen.exe and select the desired key type and length. The default value is SSH2 (RSA). Set the length to 1024. Click Generate, as shown in the following figure.

Click a few mouse clicks to generate the password. Set the password in key passhrase to prevent the server from being remotely obtained by others.

Click save private key to save the public key and private key on your computer.

3. Modify the key
Use notepad to open the public key, modify the base64 rows into one line, and remove the comments from the head and tail.

---- BEGIN SSH2 public key ----
Comment: "rsa-key-20140803"
Bytes
WEjVYBCE5V8U6lKLoWDFlgHWjm + W08mjBUbEyZx0D5oW + zS2cKkJHS1QKhBCMFwD
0nA +/4cQpFN53TTO4iny3cQnwELPS68x + Cc0NTuqu9doYarCOX08tYO/dasfsqcP
SD2psQ =
---- END SSH2 public key ----
Modify

AAAAB3NzaC1yc2EAAAABJQAAAIB... (indicates omitted) change to a row and delete the linefeed.
Save

II. Server configuration

1. selinux needs to be disabled
Two methods
Method 1:
Run the following command to temporarily disable
Setenforce 0
Method 2:
Modify the/etc/selinux/config file and set SELINUX = disabled
Save and restart the server.
2. Upload the modified public key to the server and put it in the/root/. ssh/Directory. Then, you need to set permissions for the execution.

Cat [pulbic key filename]> authorized_keys
Chmod 600 authorized_keys
Chmod 700/root/. ssh
3. Modify authorized_keys and add ssh-rsa before the Base64 string added, which are separated by spaces, as shown below:

Ssh-rsa AAAAB3NzaC1yc2EAAAABJQAAAIB... (omitted)
4. Modify the/etc/ssh/sshd_config file, find the following configuration items, and modify them as follows:

PubkeyAuthentication yes // enable key authentication
AuthorizedKeysFile. shh/authorized_keys // specify the file path
PasswordAuthentication no // disable key authentication
5. Restart the sshd service.

Service sshd restart

III. Local verification

1. Export private key to openssh private key format
Open puttygen.exe and click load to load the exported private key file.

Export the data to the openssh private key format
Click Conversions-> Export Openssh key and select the save location.
2. Use xshell and other software to log on to the server with the key. If the key can be created normally, the configuration is successful!

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.