天天看点

ssh免密登录

[root@aniu-saas-1 ~]# ssh-keygen -t rsa -P ''

Generating public/private rsa key pair.

Enter file in which to save the key (/root/.ssh/id_rsa): 

Created directory '/root/.ssh'.

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

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

The key fingerprint is:

c5:76:18:5a:c0:33:b7:8f:03:b9:a2:fe:df:16:50:1a root@aniu-saas-1

The key's randomart p_w_picpath is:

+--[ RSA 2048]----+

|       ...o      |

|        E+oo     |

|        .O=..    |

|        =o..     |

|        S+ o     |

|      . . + .    |

|     . .   o     |

|    .    ..      |

|   ........      |

+-----------------+

[root@aniu-saas-1 ~]# touch ~/.ssh/authorized_keys

[root@aniu-saas-1 ~]# cat ~/.ssh/id_rsa.pub >> ~/.ssh/authorized_keys 

[root@aniu-saas-1 ~]# chmod 600 ~/.ssh/authorized_keys 

[root@aniu-saas-1 ~]# vim /etc/ssh/sshd_config

RSAAuthentication yes

PubkeyAuthentication yes

AuthorizedKeysFile      .ssh/authorized_keys

[root@aniu-saas-1 ~]# systemctl restart sshd

[root@aniu-saas-1 ~]# ssh [email protected] 'cat >> ~/.ssh/authorized_keys' < ~/.ssh/id_rsa.pub 

'cat >> ~/.ssh/authorized_keys' < ~/.ssh/id_rsa.pub的作用是,将本地的公钥文件~/.ssh/id_rsa.pub,重定向追加到远程文件authorized_keys。

[root@aniu-saas-1 ~]# ssh [email protected] 'ps ax | grep mysql'

继续阅读