SSH password free login one step

Time:2021-11-28

SSH password free login

Server a implements password free login to server B. (Linux server based)

Implementation process


1、 Generation of server a public key

On the command line interface of server a, enter the following command to create a new [. SSH] folder under the current user directory, which contains the ID_ RSA (private key) and ID_ Rsa.pub (public key)

Server a: ~ nicholas.joey $SSH keygen - t RSA - C "your mailbox"
Server a: ~ Nicholas. Joey $CD. SSH
Server a:. SSH Nicholas. Joey $LS - al
total 40
drwx------   6 nicholas.joey  staff   192  2  3 14:13 .
drwxr-xr-x+ 47 nicholas.joey  staff  1504  2  3 14:13 ..
-rw-r--r--   1 nicholas.joey  staff   263  2  3 14:13 config
-rw-------   1 nicholas.joey  staff  2602 11 14 14:08 id_rsa
-rw-r--r--   1 nicholas.joey  staff   570 11 14 14:08 id_rsa.pub
[email protected]  1 nicholas.joey  staff  6270  2  3 09:14 known_hosts
2、 Processing of target server B

Whether the [. SSH] folder exists in the current user directory. If not, create a new [. SSH] folder and give 700 permissions.

And create the file authorized_ keys。 The ID created by server a_ Rsa.pub (public key) content copied in authorized_ Keys file.

[server B ~] $MKDIR. SSH/
MKDIR: cannot create directory '. SSH /': file already exists
[server B ~] $Chmod 700. SSH/
[server B ~] $CD. SSH/
[server B. SSH] $touch authorized_ keys
[server B. SSH] $VIM authorized_ keys
[server B. SSH] $cat authorized_ keys 
ssh-rsa ***** [email protected]

ending

By implementing the above two steps, server a can log in to server B through SSH

Server a: ~ nicholas.joey $SSH [email protected]

Authorized users only. All activities may be monitored and reported.

Last login: Wed Feb  3 16:12:41 2021 from 
[server B ~]$

You can also customize the name for password free login, and create a new config file in its server a [. SSH] folder

Joey:~ nicholas.joey$ cat .ssh/config 
#Local development environment
#Custom name
Host joey
#Server B address
HostName 192.168.0.106
#Server B user name
User root
#The verification method is public key
IdentityFile ~/.ssh/id_rsa
Joey:~ nicholas.joey$ ssh joey

Authorized users only. All activities may be monitored and reported.
[server B ~]$