1,在办公电脑生成公私钥,将公钥上传到服务器

ssh-keygen -t rsa -P 

-P表示密码,-P ” 就表示空密码,也可以不用-P参数,这样就要三车回车,用-P就一次回车。

 

2,把办公电脑~/.ssh/id_rsa.pub 内容复制到B机的 /root/.ssh/authorized_keys文件里

 

3,重启ssh服务

/etc/init.d/sshd restart

若重启时报错:

Redirecting to /bin/systemctl restart sshd.service

在云服务器 ECS Linux CentOS 7 下重启服务不再通过 service 操作,而是通过 systemctl 操作。 操作说明如下:

1. 查看 sshd 服务是否启动:

 

看到上述信息就可以确定是启动了。

2. 如果没有启动,则需要启动该服务:

systemctl start sshd.service
3. 重启 sshd 服务:

systemctl restart sshd.service
4. 设置服务开启自启:

systemctl enable sshd.service