[Linux] SSH配置了免密碼登入,登入時還要輸入密碼

tolilong發表於2016-02-25
Linux SSH配置了免密碼登入,登入時還要輸入密碼

[mon@oracle6 ~]$ ll .ssh
ls: cannot access .ssh: No such file or directory
[mon@oracle6 ~]$ ssh-keygen -t rsa
Generating public/private rsa key pair.
Enter file in which to save the key (/home/mon/.ssh/id_rsa): 
Created directory '/home/mon/.ssh'.
Enter passphrase (empty for no passphrase): 
Enter same passphrase again: 
Your identification has been saved in /home/mon/.ssh/id_rsa.
Your public key has been saved in /home/mon/.ssh/id_rsa.pub.
The key fingerprint is:
5c:0e:06:09:64:aa:ae:47:1d:9e:11:e9:58:d8:9c:36 mon@oracle6
The key's randomart image is:
+--[ RSA 2048]----+
|   =++..         |
|  .oE ..         |
|  .= o  o .      |
| .. +  o +       |
|.  o +  S .      |
|. . +            |
| o               |
|. .              |
|..               |
+-----------------+
[mon@oracle6 ~]$ ll .ssh
total 12
-rw-------. 1 mon mon 1675 Feb 21 17:16 id_rsa
-rw-r--r--. 1 mon mon  393 Feb 21 17:16 id_rsa.pub
-rw-r--r--. 1 mon mon  401 Feb 21 17:17 known_hosts


[mon@oracle6 ~]$ ssh mon@topaz "cat >> ~/.ssh/authorized_keys" < ~/.ssh/id_rsa.pub
The authenticity of host 'oracle (172.16.99.19)' can't be established.
RSA key fingerprint is b6:9f:be:8a:ad:1e:e8:c8:1f:b4:75:04:01:69:0e:5e.
Are you sure you want to continue connecting (yes/no)? yes
Warning: Permanently added 'oracle,172.16.99.19' (RSA) to the list of known hosts.
mon@topaz's password: mon




[mon@oracle6 ~]$ ssh mon@topaz
mon@topaz's password: 


ssh mon@topaz還需要輸入密碼。
baidu之後發現topaz伺服器上,的authorized_keys屬性(664)有問題,應該為600
authorized_keys的正確屬性為600
.ssh的正確屬性為700


[mon@topaz ~]$ ll -a
drwx------ 2 mon  mon  4096 Feb 21 19:13 .ssh


[mon@topaz .ssh]$ ll
total 12
-rw-rw-r-- 1 mon mon 1179 Feb 21 19:16 authorized_keys
-rw------- 1 mon mon 1675 Feb 21 19:12 id_rsa
-rw-r--r-- 1 mon mon  391 Feb 21 19:12 id_rsa.pub


修改authorized_keys的屬性為600
[mon@topaz .ssh]$ chmod 600 authorized_keys 


之後ssh mon@topaz可以正常登入。
[mon@oracle6 ~]$ ssh mon@topaz
Last login: Sun Feb 21 19:17:49 2016 from s-file-backend.domain.com


[mon@oracle6 ~]$ echo "df -P" | ssh mon@topaz
Pseudo-terminal will not be allocated because stdin is not a terminal.
Filesystem         1024-blocks      Used Available Capacity Mounted on
/dev/sda2             14877092   5685340   8423848      41% /
/dev/sda5             62216440  52317664   6687388      89% /u01
/dev/sda1               101086     11885     83982      13% /boot
tmpfs                  4194304   1063292   3131012      26% /dev/shm
/dev/sdc1             82567188    705556  77667464       1% /u02

來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/24237320/viewspace-1994776/,如需轉載,請註明出處,否則將追究法律責任。

相關文章