【Linux】SSH免密登录配置
一、Ubuntu ssh免密登录
1、生成密钥对
[root@temp-ubuntu-1804-server:~]# ssh-keygen -t rsa Generating public/private rsa key pair. Enter file in which to save the key (/root/.ssh/id_rsa): Enter passphrase (empty for no passphrase): Enter same passphrase again: 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: SHA256:XmlRk5OLf2gX9tUeE0OPbTCDG5jBWXLy6nbM02tfqps root@temp-ubuntu-1804-server.janzen.com The key's randomart image is: +---[RSA 2048]----+ | .+*=+=. | | =**. O.| | ...=. B| | .+o o+o| | S =. o ++| | . + o+.o o| | . o.=o. .| | . . o.o.| | E+o..| +----[SHA256]-----+ [root@temp-ubuntu-1804-server:~]# ls .ssh/ authorized_keys id_rsa id_rsa.pub known_hosts
2、被控端导入公钥
[root@temp-ubuntu-1804-server:~]# cat .ssh/authorized_keys ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQCwohqZD2j3TYLokECPl0Tx3h7yMbEQubtFkr4Oy7MLOehZPIS6bwkbd7MwVORsC5wFc4lmu4+3N8ZH6hNarSeuKTRZRMg/RYmQcxaO2doXfpvTHTE+4A2Vcs3Tou0ugjXOi+wuY3878Kz9rxCucjlIyZDu6bNYcsFuA918HUOAMr4XqdzoXTYjYFs9hRR51T6nBk+eCNfj7EDULmkkOSd7uZOd5bmBw/KZjxkSbEIgr1dTAZCzwMjvzLAqXibYQ4QmOw0RIIS5EAouS0RN+ukdUNgHhYz4sdLkndXXqdwf6AkFj2N0d8+QEOco4Wpa2rVDpAzEViKIe9TtnaX/+OFp root@temp-ubuntu-1804-server.janzen.com
3、修改sshd配置
[root@temp-ubuntu-1804-server:~]# vim /etc/ssh/sshd_config [root@temp-ubuntu-1804-server:~]# cat /etc/ssh/sshd_config | grep ^[^#] PermitRootLogin yes PubkeyAuthentication yes AuthorizedKeysFile .ssh/authorized_keys .ssh/authorized_keys2 ChallengeResponseAuthentication no UsePAM yes X11Forwarding yes PrintMotd no AcceptEnv LANG LC_* Subsystem sftp /usr/lib/openssh/sftp-server PasswordAuthentication yes [root@temp-ubuntu-1804-server:~]# systemctl restart sshd
4、客户端导入私钥
[root@temp-ubuntu-1804-server:~]# scp .ssh/id_rsa 10.0.0.250:~/.ssh/ id_rsa 100% 1675 2.3MB/s 00:00 [root@Client-Ubuntu1804-250:~]# ls .ssh/ authorized_keys id_rsa known_hosts
5、xshell 导入私钥