压缩版命令
#一键重置本地免密登陆 (chattr -i /root/.ssh/authorized_keys) && (rm -rf /root/.ssh) && (mkdir /root/.ssh) && (ssh-keygen -t dsa -P '' -f ~/.ssh/id_dsa) && (cat ~/.ssh/id_dsa.pub >> ~/.ssh/authorized_keys) && (chmod 700 ~/.ssh) && (chmod 644 ~/.ssh/authorized_keys) && (ssh localhost -o StrictHostKeyChecking=no)
#删除原有证书 并 生成新证书 (chattr -i /root/.ssh/authorized_keys) && (rm -rf /root/.ssh) && (mkdir /root/.ssh) && (ssh-keygen -t rsa) && (ssh-copy-id -i ~/.ssh/id_rsa.pub root@localhost) && (chmod 600 ~/.ssh/authorized_keys)
#删除原有证书 chattr -i /root/.ssh/authorized_keys rm -rf /root/.ssh mkdir /root/.ssh (chattr -i /root/.ssh/authorized_keys) && (rm -rf /root/.ssh) && (mkdir /root/.ssh) #生成证书 ssh-keygen -t rsa ssh-copy-id -i ~/.ssh/id_rsa.pub root@localhost (ssh-keygen -t rsa) && (ssh-copy-id -i ~/.ssh/id_rsa.pub root@localhost) #若是没有authorized_keys这个文件必须用touch命令先创建这个文件,然后将文件#的权限赋值为600. chmod 600 ~/.ssh/authorized_keys #验证 ssh localhost #成功 Last login: Tue Dec 3 10:42:24 2019 from 127.0.0.1
一、首先退出刚才的 ssh,就回到了我们原先的终端窗口,然后利用 ssh-keygen 生成密钥,并将密钥加入到授权中:
exit # 退出刚才的 ssh localhost
cd ~/.ssh/ # 若没有该目录,请先执行一次ssh localhost
ssh-keygen -t rsa # 会有提示,都按回车就可以
cat ./id_rsa.pub >> ./authorized_keys # 加入授权
二、
1,登录ssh localhost
2,(ssh-keygen -t dsa -P ‘’ -f ~/.ssh/id_dsa)&&
cat ~/.ssh/id_dsa.pub >> ~/.ssh/authorized_keys
3,再次执行ssh localhost
4,要保证:
~/.ssh需要是700权限
authorized_keys需要是644权限
(chmod 700 ~/.ssh) && (chmod 644 ~/.ssh/authorized_keys)