线上经常因为系统盘的故障或者是SAS卡驱动的问题使得/或者/home掉了,那么ssh信任登录的时候就会因为找不到AuthorizedKeysFile里面指定的文件而造成无法登录服务器。解决的思路就是可以设置多个authorized_keys,比如放一份到内存里面(可能会存在一些安全问题,不过内部系统应该可控)。openssh到5.8版本以上,可以AuthorizedKeysFile后面支持多个路径,之前的版本比如centos 5(OpenSSH_4.3p2)的可以设置AuthorizedKeysFile2。

sshd_config设置AuthorizedKeysFile     %h/.ssh/authorized_keys /sshkeys/.ssh/authorized_keys或者AuthorizedKeysFile2     /sshkeys/.ssh/authorized_keys

需要注意/run/shm/或者/dev/shm的权限问题。最好在根文件系统下单独建立个目录,把shm下的bind过去mount –bind /dev/shm/sshkeys/ /sshkeys/登录的时候可以看到服务端会读取2个authorized_keys文件。

Sep  6 14:24:07 root sshd[17173]: debug1: userauth-request for user root service ssh-connection method publickeySep  6 14:24:07 root sshd[17173]: debug1: attempt 2 failures 1Sep  6 14:24:07 root sshd[17172]: debug1: temporarily_use_uid: 0/0 (e=0/0)Sep  6 14:24:07 root sshd[17172]: debug1: trying public key file /root/.ssh/authorized_keysSep  6 14:24:07 root sshd[17172]: debug1: restore_uid: 0/0Sep  6 14:24:07 root sshd[17172]: debug1: temporarily_use_uid: 0/0 (e=0/0)Sep  6 14:24:07 root sshd[17172]: debug1: trying public key file /sshkeys/.ssh/authorized_keysSep  6 14:24:07 root sshd[17172]: debug1: matching key found: file /sshkeys/.ssh/authorized_keys, line 8~