Linux记录-配置无密码登录

  1. 配置前,先安装 SSH 服务。  
  2. ssh-keygen -t dsa -P '' -f ~/.ssh/id_dsa  
  3. cat ~/.ssh/id_dsa.pub >> ~/.ssh/authorized_keys  
  4. #把 id_rsa.pub 追加到授权的 key 里面去、  
  5. chmod 600 ~/.ssh/authorized_keys #授权  
  6. vim /etc/ssh/sshd_config  
  7. RSAAuthentication yes # 启用 RSA 认证  
  8. PubkeyAuthentication yes # 启用公钥私钥配对认证方式  
  9. AuthorizedKeysFile .ssh/authorized_keys # 公钥文件路径(和上面生成  
  10. 的文件同)  
  11. service sshd restart#重启 SSHD 服务  
  12. 验证 ssh,# ssh ip 或 ssh localhost

------------------------------------------------------------------------------------------------------------------------

当出现Permission denied (publickey,gssapi-keyex,gssapi-with-mic) 警告的时候,恭喜你,你已经离成功很近了。

(1)首先:配置ssh服务器配置文件。

在root 用户下才能配置。

vi /etc/ssh/sshd_config

权限设为no:

#PermitRootLogin yes

#UsePAM yes

#PasswordAuthentication yes

如果前面有# 号,将#号去掉,之后将yes修改为no。

修改之后为:

PermitRootLogin no

UsePAM no

PasswordAuthentication no

权限设为yes:

RSAAuthentication yes

PubkeyAuthentication yes

(2)重启sshd服务

systemctl restart sshd.service

systemctl status sshd.service #查看ssh服务的状态

#systemctl start sshd.service  #开启ssh服务

#sytemctl enable sshd.service #ssh服务随开机启动,还有个disabled

#systemctl stop sshd.ervice #停止

正常情况下应该是Active:active(running)

(3)修改文件夹以及文件的权限。

#chmod 700 /home/Hadoop/.ssh

#chmod 644 /home/Hadoop/.ssh/authorized_keys

--------------------------------------------------------------------------------------------------------------------------------------

三步到位

ssh-keygen  回车
ssh-copy-id -i /home/sfapp/.ssh/id_rsa.pub [email protected]
ssh-copy-id -i /home/sfapp/.ssh/id_rsa.pub [email protected]
ssh [email protected]
ssh [email protected]

猜你喜欢

转载自www.cnblogs.com/xinfang520/p/10281484.html
今日推荐