222SSH免密码登录配置222

通过配置ssh,实现无需输入密码就能访问远程用户222

Posted by carm on April 2, 2019

SSH免密码登录配置222

备忘录–openssh

声明:原创文章,转载自由,但需注明出处。

系统环境

  • Centos7.2
  • openssh6.6

生成秘钥

# 假设当前用户为www
$ ssh-keygen -t dsa -P '' -f ~/.ssh/id_dsa
$ cat ~/.ssh/id_dsa.pub >> ~/.ssh/authorized_keys
$ chmod 0600 ~/.ssh/authorized_keys

检查ssh代理是否开启

$ ps -aux | grep 'agent'
# 若代理没启动,则启动它,命令如下:
$ ssh-agent

测试

$ ssh localhost
# 若无需输入密码,则配置完成

其他用户无密码连接

若其他用户需无密码访问www,如用户fool登录www,则将用户fool生成的公钥id_dsa.pub拷贝到www用户的~/.ssh/authorized_keys文件中

# fool 用户
# fool用户公钥重命名
$ cp ~/.ssh/id_dsa.pub ~/.ssh/fool.pub
# 将fool的公钥拷贝到www的用户目录下。注意:拷贝过程需要输入www用户登录密码
$ scp ~/.ssh/fool.pub www@host:/home/www
# 将fool.pub添加到.ssh/authorized_keys文件中
$ cat ~/fool.pub >> ~/.ssh/authorized_keys
# fool测试登录www
$ ssh www@host
# 若无需输入密码成功登录,则配置成功