案件听起来很简单。我使用“服务器”上的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=<...>)
由于~/.ssh
默认情况下是“ authorized_keys”文件,因此在我实际登录之前不会解密该文件,因此将该文件移至/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-密钥验证。我在这里搜索此问题,但大多数都得到了相同的说明。但是,如果没有密码,我仍然无法登录。
然后,我做了一些测试,在服务器上生成了一对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,也没有起作用...
您的问题是缺少日志产生的信息sshd
:
/var/log/auth.log
错误消息说明了有关的错误权限/home
。
手册页中sshd
添加了以下条件:
~/.ssh/authorized_keys
如果此文件,
~/.ssh
目录或用户的主目录可由其他用户写入,则该文件可以被未经授权的用户修改或替换。在这种情况下,sshd
除非StrictModes
选项设置为“ no”,否则将不允许使用它。
因此,选择是修复权限,或者如果您需要使该/home
组可写,请StrictModes no
在中使用sshd_config
。
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句