如何在 Debian 上配置 sshd 以使用公钥认证?

Chr*_*ard 5 debian ssh ssh-keys

我正在开发一个(Debian)Dreamhost VPS,它似乎只想要基于密码的身份验证:添加我的 RSA 和 DSA 公钥~/.ssh/authorized_keys并没有改变需要密码登录的行为。

如何设置服务器才能接受~/.ssh/authorized_keys

Aro*_*eel 17

您需要进行/etc/ssh/sshd_config如下编辑:

# Both of these are probably already there, but commented
PubkeyAuthentication yes
# The next line makes sure that sshd will look in 
# $HOME/.ssh/authorized_keys for public keys
AuthorizedKeysFile      %h/.ssh/authorized_keys
Run Code Online (Sandbox Code Playgroud)

此外,如果您想完全禁用密码身份验证(这通常是一个好主意,如果您使用密钥对),请添加以下内容:

# Again, this rule is already there, but usually defaults to 'yes'
PasswordAuthentication no
Run Code Online (Sandbox Code Playgroud)

之后,通过发出重新启动ssh/etc/init.d/sshd restart,您应该没问题!

以上假设您已经正确创建了.ssh具有适当权限的目录。

这意味着您设置chmod 0700~/.ssh.