目标
在主机A中设置无密码登陆访问主机B,用于svn钩子post-commit文件设置svn服务器(主机A)与web服务器(主机B)之间文件提交后自动同步。
服务器
SVN主机A:192.168.1.118 用户 svnuser
WEB主机B:192.168.1.188 用户 root
步骤
主机A中执行如下:
1、cd ~/.ssh
2、ssh-keygen -t rsa
然后一直按回车键,就会按照默认的选项将生成的密钥保存在.ssh/id_rsa文件中。
[svnuser@localhost bin]$ ssh-keygen -t rsa
Generating public/private rsa key pair.
Enter file in which to save the key (/home/svnuser/.ssh/id_rsa):
Created directory '/home/svnuser/.ssh'.
Enter passphrase (empty for no passphrase):
Enter same passphrase again:
Your identification has been saved in /home/svnuser/.ssh/id_rsa.
Your public key has been saved in /home/svnuser/.ssh/id_rsa.pub.
The key fingerprint is:
c5:ae:e4:6b:21:df:cb:c7:bb:90:4d:ad:46:04:45:27 svnuser@localhost.localdomain
The key's randomart image is:
+--[ RSA 2048]----+
| .oE . |
| . . o |
| o . |
| o . . |
| S . o . |
| .o.. = . |
| oooo.+ |
| oo.oo |
| .. oooo |
+-----------------+
3、cp id_rsa.pub authorized_keys
这步完成后,正常情况下就可以无密码登录本机了,即ssh localhost,无需输入密码。
[svnuser@localhost logs]$ ssh localhost
Last login: Sun Feb 14 15:19:14 2016 from localhost
[svnuser@localhost ~]$
4、scp authorized_keys root@192.168.1.188:/root/.ssh
把刚刚产生的authorized_keys文件拷一份到主机B上。
5、chmod 700 authorized_keys
进入主机B的.ssh目录,改变authorized_keys文件的许可权限。
执行完毕以上5步骤后,一般情况会成功配置,注意用户的身份。