4-3·SSH免密、秘钥验证、端口转发
2018-01-09 16:00
260 查看
一·配置SSH服务器使用秘钥验证登录。为客户端创建私钥,为服务器创建公钥。
1)生成秘钥。$ ssh-keygen -t rsa //生成,一路回车 $ mv ~/.ssh/id_rsa.pub ~/.ssh/authorized_keys //将生成的秘钥保存 $ chmod 600 ~/.ssh/authorized_keys //给与权限
2)将生成的秘钥传送给客户端,用来登录验证!
$ mkdir ~/.ssh $ chmod 700 ~/.ssh $ scp 主机名@IP:/home/lee/.ssh/id_rsa ~/.ssh/ //传递给客户端 $ ssh -i ~/.ssh/id_rsa 主机名@IP //秘钥连接
3)设置SSH允许免密登录!
$ vi /etc/ssh/sshd_config #密码验证关闭 PasswordAuthentication no ChallengeResponseAuthentication no UsePAM yes $ systemctl restart sshd //重启服务
二·端口转发
可以通过SSH端口转发将端口转发到另一个端口配置本地的22端口转换为本地的8080
[root@localhost ~]# ssh -L 0.0.0.0:8080:localhost:5901 root@localhost root@localhost's password: [root@localhost ~]# netstat -lnp | grep 8080 tcp 0 0 0.0.0.0:8080 0.0.0.0:* LISTEN 24460/ssh //检查发现,SSH端口变为8080 [root@localhost ~]#