SSH免密登录CentOS7

本机传送id_rsa.pub

1
$ scp .ssh/id_rsa.pub user@ip:/root/id_rsa.pub

服务器

1
2
3
$ cat id_rsa.pub >> .ssh/authorized_keys
$ chmod 700 .ssh
$ chmod 600 .ssh/authorized_keys

服务器额外配置(centos7.4以下)

1
$ vim /etc/ssh/sshd_config

如下配置,7.4及更高版本不需要

1
2
3
RSAAuthentication yes
PubkeyAuthentication yes
AuthorizedKeysFile .ssh/authorized_keys

重启服务

1
$ service ssh restart

本机登录

方式一:用户名@IP

1
$ ssh user@ip

方式二:别名

配置.ssh/config

1
2
3
4
5
Host xxx # 别名
Hostname xxx.xxx.xxx.xxx # ip
Port 22
User xxx # 用户名
IdentityFile ~/.ssh/id_rsa
1
$ ssh xxx
uyaki 支付宝支付宝
uyaki 微信微信
0%