[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 root@10.26.100.30 '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 root@10.26.100.20 'ps ax | grep mysql'

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

 3696 ?        S      0:00 grep mysql