首先要在需要连接的远端主机(这里我要连接的是阿里云的服务器,系统是CentOS7)上安装ssh服务并开启,
[root@ecssher6j ~]# yum install -y openssh-server # 安装openssh服务端
[root@ecssher6j ~]# yum install -y openssh-clients #安装openssh客户端,可以不安装
[root@ecssher6j ~]# service sshd start # 临时开启sshd服务
[root@ecssher6j ~]# chkconfig sshd on # 永久开启sshd服务,服务器重启也生效
[root@ecssher6j ~]# service sshd status # 查看sshd服务运行状态
openssh-daemon (pid 1384) 正在运行... # 显示正在运行
[root@ecssher6j ~]# (umask 0077; ssh-keygen) # 生成ssh密钥对
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