Linux SSH/SCP use Public key authentication method to log in __linux

Source: Internet
Author: User
Tags file permissions

Reprint Address: http://hi.baidu.com/edeed/item/13842c2523a2ae0977272c6d

For example, to the 192.168.41.76 server, do not enter a user password that is the root user login 192.168.41.75 server.

1 Create public and private keys on 192.168.41.76

[192.168.41.76]# ssh-keygen-t RSA

Generating public/private RSA key pair.

Enter file in which to save the key (//.SSH/ID_RSA)://Direct return, default location. Ssh/id_rsa

Enter passphrase (empty for no passphrase)://Direct return, no password

Enter same passphrase again://Direct return, no password

Your identification has been saved in//.ssh/id_rsa.

Your public key has been saved in//.ssh/id_rsa.pub.

The key fingerprint is:

f3:66:3d:23:9f:cf:78:0b:f8:58:8f:3d:ee:ba:55:99 Root@dw_test1

[192.168.41.76]# ll ~/.ssh

-RW-------1 root root 883 June 14:25 Id_rsa

-rw-r--r--1 root root 221 June 14:25 Id_rsa.pub

Description

-t RSA represents an SSH-generated key for RSA type, which is the default behavior. You can also perform a key that generates a DSA type. At this point the view. SSH folder found more than two files, Id_rsa is the private key, Id_rsa.pub is the public key.


2) Confirm whether there is a ~/.ssh directory on the 192.168.41.75, without first establishing

[192.168.41.75]# ll ~/.ssh

[192.168.41.75]# mkdir ~/.ssh


3 Use SCP to copy public key id_rsa.pub to 192.168.41.75 on 192.168.41.76

[192.168.41.76]# SCP ~/.ssh/id_rsa.pub root@192.168.41.75:~/

root@192.168.41.75 ' s Password://Enter remote server root login password


4 Add id_rsa.pub content to the ~/.ssh/authorized_keys file of the corresponding user on 192.168.41.75 and delete id_rsa.pub file

[192.168.41.75]# cat ~/id_rsa.pub >> ~/.ssh/authorized_keys

[192.168.41.75]# rm-f Id_rsa.pub


5 so on the 192.168.41.76 can not enter the password directly to the root user login 192.168.41.75, but also a known_hosts file

[192.168.41.76]# ssh 192.168.41.75

[192.168.41.76]# ll ~/.ssh

-rw-r--r--1 root root 221 2009-06-30 14:25:32.000000000 +0800 id_rsa.pub

-RW-------1 root 883 2009-06-30 14:25:32.000000000 +0800 Id_rsa

-rw-r--r--1 root root 223 2009-06-30 14:30:26.000000000 +0800 known_hosts


6) Note

The permissions for the SSH directory must be 0700,. ssh/authorized_keys file permissions must be 0600 or public key authentication will not take effect. If you want to go directly to other users of 192.168.41.75, you need to append the public key to another user's Authorized_keys file.

--end--

#Linux

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.