创建ssh信任关系

copy公钥
1
2
3
4
5
6
#在本地生成公钥和密钥:
ssh-keygen -t rsa
#将本机生成的公钥发送到服务器上(建立信任关系):
ssh-copy-id -i C:/Users/UserName/.ssh/id_rsa.pub root@server_ip #UserName是电脑的用户名
#测试ssh远程登录是否成功:
ssh root@server_ip
远程服务端会有.ssh目录
1
2
3
4
5
[lvshen@wade ~]$ ls -al
total 56
...
drwxr-xr-x 2 lvshen lvshen 4096 Jan 5 10:45 .ssh
...
修改.ssh权限
1
2
[lvshen@wade ~]$ chmod 700 .ssh
[lvshen@wade ~]$ chmod 600 .ssh/authorized_keys

root用户下操作

cat /var/log/secure 查看系统的安全日志,然后再安全日志中看到SSH登录过程中提示了如下错误:

1
2
3
...
May 30 16:53:36 wade sshd[30159]: Authentication refused: bad ownership or modes for directory /git
...
解决SSH Authentication Refused
1
2
[root@wade ~]# chmod g-w /home/lvshen
[root@wade ~]# service sshd restart
赋予root权限

修改 /etc/sudoers 文件,找到下面一行,在root下面添加一行,如下所示:

1
2
3
#Allow root to run any commands anywhere
root ALL=(ALL) ALL
git ALL=(ALL) ALL