这个案例听起来很简单。我在“服务器”上使用 eCryptFS 加密了我的主文件夹,如下所示:
/home/<user_name>/.Private on /home/<user_name> type ecryptfs (ecryptfs_check_dev_ruid,
ecryptfs_cipher=aes,ecryptfs_key_bytes=16,ecryptfs_unlink_sigs,ecryptfs_sig=<...>,
ecryptfs_fnek_sig=<...>)
因为默认情况下“authorized_keys”文件在~/.ssh
,在实际登录之前不会解密,所以我将该文件移动到/home/ssh/<user_name>/authorized_keys
。的权限/home/ssh/<user_name>
是755,authorized_keys
文件的权限是644。该文件包含我想要登录的机器的公钥。
然后我将 中的“AuthorizedKeysFile”选项更改/etc/ssh/sshd_config
为/home/ssh/%u/authorized_keys
。正如本手册所建议的那样:https://help.ubuntu.com/community/SSH/OpenSSH/Keys以及这篇文章:https://stephen.rees-carter.net/thought/encrypted-home-directories-ssh-key-authentication。我在这里搜索了这个问题,但得到的指导大多相同。但是,我仍然无法在没有密码的情况下登录。
然后我做了一些测试,在服务器上生成了一对 SSH 密钥(我想通过 SSH 进入),并将公钥复制到/home/ssh/<user_name>/authorized_keys
。然后我发现,如果不使用密码,我甚至无法在该服务器上登录localhost
。因此,我假设由于某种原因,SSH 守护进程根本没有加载 authorized_keys 文件。我也尝试将文件放在原始位置~/.ssh
,但仍然无法进行公钥认证。
附件是我的sshd_config
:
# Package generated configuration file
# See the sshd_config(5) manpage for details
# What ports, IPs and protocols we listen for
Port 22
# Use these options to restrict which interfaces/protocols sshd will bind to
#ListenAddress ::
#ListenAddress 0.0.0.0
Protocol 2
# HostKeys for protocol version 2
HostKey /etc/ssh/ssh_host_rsa_key
HostKey /etc/ssh/ssh_host_dsa_key
HostKey /etc/ssh/ssh_host_ecdsa_key
HostKey /etc/ssh/ssh_host_ed25519_key
#Privilege Separation is turned on for security
UsePrivilegeSeparation yes
# Lifetime and size of ephemeral version 1 server key
KeyRegenerationInterval 3600
ServerKeyBits 1024
# Logging
SyslogFacility AUTH
LogLevel INFO
# Authentication:
LoginGraceTime 120
PermitRootLogin without-password
StrictModes yes
RSAAuthentication yes
PubkeyAuthentication yes
AuthorizedKeysFile /home/ssh/%u/authorized_keys
# Don't read the user's ~/.rhosts and ~/.shosts files
IgnoreRhosts yes
# For this to work you will also need host keys in /etc/ssh_known_hosts
RhostsRSAAuthentication no
# similar for protocol version 2
HostbasedAuthentication no
# Uncomment if you don't trust ~/.ssh/known_hosts for RhostsRSAAuthentication
#IgnoreUserKnownHosts yes
# To enable empty passwords, change to yes (NOT RECOMMENDED)
PermitEmptyPasswords no
# Change to yes to enable challenge-response passwords (beware issues with
# some PAM modules and threads)
ChallengeResponseAuthentication no
# Change to no to disable tunnelled clear text passwords
#PasswordAuthentication yes
# Kerberos options
#KerberosAuthentication no
#KerberosGetAFSToken no
#KerberosOrLocalPasswd yes
#KerberosTicketCleanup yes
# GSSAPI options
#GSSAPIAuthentication no
#GSSAPICleanupCredentials yes
X11Forwarding yes
X11DisplayOffset 10
PrintMotd no
PrintLastLog yes
TCPKeepAlive yes
#UseLogin no
#MaxStartups 10:30:60
#Banner /etc/issue.net
# Allow client to pass locale environment variables
AcceptEnv LANG LC_*
Subsystem sftp /usr/lib/openssh/sftp-server
# Set this to 'yes' to enable PAM authentication, account processing,
# and session processing. If this is enabled, PAM authentication will
# be allowed through the ChallengeResponseAuthentication and
# PasswordAuthentication. Depending on your PAM configuration,
# PAM authentication via ChallengeResponseAuthentication may bypass
# the setting of "PermitRootLogin without-password".
# If you just want the PAM account and session checks to run without
# PAM authentication, then enable this but set PasswordAuthentication
# and ChallengeResponseAuthentication to 'no'.
UsePAM yes
该authorized_keys
文件位于此处:
$ ll
total 24K
drwx------ 2 root root 16K Feb 26 19:23 lost+found
drwxrwxr-x 3 root root 4.0K Mar 1 13:12 ssh
drwx------ 22 <user_name> <user_name> 4.0K Mar 1 13:42 <user_name>
$ cd ssh
$ ll
total 4.0K
drwxr-xr-x 2 <user_name> <user_name> 4.0K Mar 1 13:12 <user_name>
$ cd <user_name>
$ ll
total 4.0K
-rw-r--r-- 1 <user_name> <user_name> 790 Mar 1 13:32 authorized_keys
$
我也尝试将(目录和文件的)权限更改为 700 和 600,但也没有用......
答案1
您的问题缺少由以下人员生成的日志中的信息sshd
:
/var/log/auth.log
错误消息表明 上的权限有误/home
。
手册页sshd
添加了此条件:
~/.ssh/authorized_keys
如果此文件、
~/.ssh
目录或用户的主目录是可由其他用户写入,则该文件可能会被未经授权的用户修改或替换。在这种情况下,除非选项设置为“否”,sshd
否则将不允许使用它。StrictModes
因此,选择是修复权限,或者如果您需要让/home
组可写,请StrictModes no
在您的中使用sshd_config
。