shell下实现自动登录ssh的方法
先用ssh-keygen生成密钥和公钥,然后把公钥copy到对方节点去...,具体参考下面的步骤。
[@more@]ssh-keygen -t rsa 或 ssh-keygen -d (dsa) => 产生出 id_rsa, id_rsa.pub
scp id_rsa.pub server_hostname:~/.ssh/
ssh server_hostname
cat .ssh/id_rsa.pub >> .ssh/authorized_keys
cat .ssh/id_rsa.pub >> .ssh/authorized_keys2
同时Copy到对方节点。
即可
这样子就可以key认证登入,不需输入密码
然后,今天做我们的生产环境的时候,发现有6台机器全部都通过了ssh自动连接到远程主机,惟独有一台机器不行,在网上查了很久,终于得到了一个最终的答案!下面的是参考文章,我的解决办法也是设置了对应的目录权限就可以了!
--------------------------------------------------------------------
ssh-keygen后,仍提示需要密码
[oracle@dbrac3 opt]$ chmod 700 ~/.ssh
[oracle@dbrac3 opt]$ ssh-keygen -t rsa
[oracle@dbrac3 opt]$ ssh-keygen -t dsa
[oracle@dbrac3 opt]$ cat ~/.ssh/id_rsa.pub >> ~/.ssh/authorized_keys
[oracle@dbrac3 opt]$ cat ~/.ssh/id_dsa.pub >> ~/.ssh/authorized_keys
[oracle@dbrac3 opt]$ ssh dbrac3 date
Wed Jul 16 02:25:23 CST 2008
...
debug1: Unspecified GSS failure. Minor code may provide more information
Unknown code krb5 195
Unknown code krb5 195
Unknown code krb5 195
debug1: Trying private key: /opt/oracle/.ssh/identity
debug1: Offering public key: /opt/oracle/.ssh/id_rsa
debug1: Authentications that can continue: publickey,gssapi-with-mic,password
debug1: Offering public key: /opt/oracle/.ssh/id_dsa
debug1: Authentications that can continue: publickey,gssapi-with-mic,password
debug1: Next authentication method: password oracle@dbrac3's password:
debug1: Authentication succeeded (password).
...
...
debug1: Unspecified GSS failure. Minor code may provide more information
Unknown code krb5 195
Unknown code krb5 195
Unknown code krb5 195
debug1: Trying private key: /opt/oracle/.ssh/identity
debug1: Offering public key: /opt/oracle/.ssh/id_rsa
debug1: Server accepts key: pkalg ssh-rsa blen 277
debug1: read PEM private key done: type RSA
debug1: Authentication succeeded (publickey).
...
Jul 16 02:25:23 dbrac3 sshd[5974]: pam_unix(sshd:session): session closed for user oracle
[root@dbrac3 ~]# tail -f /var/log/secure
Jul 16 02:25:17 dbrac3 sshd[5947]: Authentication refused: bad ownership or modes for directory /opt/oracle
Jul 16 02:25:17 dbrac3 sshd[5947]: Authentication refused: bad ownership or modes for directory /opt/oracle
total 316
drwxrwxr-x 20 oracle dba 4096 Jul 16 02:13 oracle
total 324
drwxr-xr-x 8 oracle dba 4096 Jul 12 07:46 oracle
[oracle@dbrac3 opt]$ ll
total 316
drwxr-xr-x 20 oracle dba 4096 Jul 16 02:13 oracle
Wed Jul 16 02:28:53 CST 2008
来自 “ ITPUB博客 ” ,链接:http://blog.itpub.net/21484429/viewspace-1023089/,如需转载,请注明出处,否则将追究法律责任。
转载于:http://blog.itpub.net/21484429/viewspace-1023089/