我只是用openssh-server设置了一个vanilla ubuntu lucid(10.04)系统。 我试图设置公钥authentication,只有当我第一次连接使用密码authentication,并保持打开该会话才有效。 所有新的并发会话将使用publickey。
我已经采取了所有步骤,以确保正确的权限在我的服务器端主目录。
chmod go-w ~/ chmod 700 ~/.ssh chmod 600 ~/.ssh/authorized_keys
我的客户端RSA 2048位公钥被附加(仅一行)到authorized_keys文件中。 我的RSA密钥也有空白密码。
我很困惑什么可能会导致这一点。 我知道它必须是我的服务器configuration的东西。 我听说如果configuration不够“安全”,它不会允许公钥authentication,但我很困惑,可能是什么。
# Authentication: LoginGraceTime 120 PermitRootLogin no StrictModes yes RSAAuthentication yes PubkeyAuthentication yes #AuthorizedKeysFile %h/.ssh/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
其余的是默认的。 PublicKey的作品,但不是第一届会议。
提前致谢!
如果你有一个encryption的主目录,Ubuntu使用EcryptFS的方式,那么这将解释你正在经历的。 您的第一次密码login后,您的〜/ .ssh / authorized_keys第一次变得可用。
允许直接通过ssh密钥login的一种方法是在主目录之外的特定AuthorizedKeysFile 。 这可以通过在path中使用%u(user)而不是%h(home目录)来完成。 另一种select是将〜/ .ssh / authorized_keys的副本放入主目录的“未安装”版本中。 这是EcryptFS挂载下的东西。
然而,不知道这些解决scheme对你来说真的有多好。 您仍然(种)需要使用您的密码login才能访问您的常规主目录。 这是您的用户密码,用于解开装载/解密EcryptFS主目录所需的密码。 是的,你仍然可以手动安装/解密,但这几乎是一个不同的问题。
我的猜测是,一旦你使用密码authentication进行login,它就会工作,因为在客户端你已经设置了ControlMaster / ControlPath,允许重复使用连接来进行后续连接。
尝试通过将LogLevel设置为DEBUG3来提高服务器端的日志级别,并挖掘日志(/var/log/auth.log)以查看发生了什么事情。
在客户端添加-vvv到ssh命令行以查看客户端正在使用的密钥。
有了这两个信息,你应该能够弄清楚什么是对的。
您的authorized_keys文件需要位于.ssh文件夹中,并且应具有644个权限。
cp〜/ .ssh / authorized_keys / etc / authorized_keys
并更改/ etc / ssh / sshd_config
AuthorizedKeysFile / etc / authorized_keys
并重新加载sshd /etc/init.d/ssh重新启动