Linux:SSH免密码登录

1.使用包管理器安装openssh:

  本人的系统是Arch Linux,因此安装命令为:sudo pacman -S openssh

2.使用ssh-keygen命令创建公钥:

  #ssh-keygen -t rsa

  程序会提示存放的目录,可以不做修改,直接回车两次,会在/home/用户目录/下生成.ssh文件夹。

3.将.ssh目录中的id_rsa.pub这个文件拷贝到要登录的服务器的.ssh目录中,然以再运行以下命令来将公钥导入到.ssh/authorized_key文件中

  cat ~/.ssh/id_rsa.pub >> ~/.ssh/authorized_keys

4.设置权限
  将服务器上 ~/.ssh权限设置为700,~/.ssh/authorized_keys的权限设置为600

5.如果服务器没有开启sshd服务,需要在服务器上开启

  Arch Linux上的命令为:sudo systemctl start sshd.service

 


在服务器上开启sshd服务时,有时会报如下错误:
  Could not load host key: /etc/ssh/ssh_host_key
  Could not load host key: /etc/ssh/ssh_host_rsa_key
  Could not load host key: /etc/ssh/ssh_host_dsa_key
  Disabling protocol version 1. Could not load host key
  Disabling protocol version 2. Could not load host key
  sshd: no hostkeys available — exiting

可以在服务器上通过如下办法解决:

  #ssh-keygen -t dsa -f /etc/ssh/ssh_host_dsa_key
  #ssh-keygen -t rsa -f /etc/ssh/ssh_host_rsa_key

重新开启sshd服务即可。

 

  

posted on 2015-09-21 14:14  看云  阅读(414)  评论(0编辑  收藏  举报

导航

http://home.cnblogs.com/group/topic/8550.html