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'

 3680 ?        Ss     0:00 bash -c ps ax | grep mysql

 3696 ?        S      0:00 grep mysql


發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章