ssh 无密码登录linux

1. mkdir -p /home/用户名/.ssh

2. 保证本地机器生成公钥和私钥,并把公钥追加到远程机器的authorized_keys文件里
可以
windows上执行ssh-keygen,复制windows C:\Users\用户名\.ssh\id_rsa.pub公钥文件内容到linux /home/用户名/.ssh/authorized_keys文件
cat ~/.ssh/id_rsa.pub | ssh 用户名@linuxhostname "cat >> ~/.ssh/authorized_keys"
或者
在linux上执行ssh-keygen,复制/home/用户名/.ssh目录到windows C:\Users\用户名\.ssh
cat ~/.ssh/id_rsa.pub >> ~/.ssh/authorized_keys

3.
chmod 700 ~ 

chmod 700 ~/.ssh

.ssh目录下的authorized_keys文件需要600或644权限
chmod 600 ~/.ssh/authorized_keys

4.root权限
vi /etc/ssh/sshd_config
PubkeyAuthentication yes
AuthorizedKeysFile /etc/ssh/keys/%u/authorized_keys2 /home/%u/.ssh/authorized_keys

 

ssh修改默认端口-涉及到selinux

centos6下修改ssh默认端口为223 (请自由发挥,实验只做参考),且不关闭selinux,不关闭iptables。

https://cloud.tencent.com/developer/news/235441



systemctl restart sshd

5.ssh 用户名@linuxhostname

posted @ 2020-05-14 15:32  tonggc1668  阅读(114)  评论(0编辑  收藏  举报