![为 SFTP 启用 DSA 密钥认证,同时仍保留密码登录作为可选项(Ubuntu 12.04)](https://linux22.com/image/609692/%E4%B8%BA%20SFTP%20%E5%90%AF%E7%94%A8%20DSA%20%E5%AF%86%E9%92%A5%E8%AE%A4%E8%AF%81%EF%BC%8C%E5%90%8C%E6%97%B6%E4%BB%8D%E4%BF%9D%E7%95%99%E5%AF%86%E7%A0%81%E7%99%BB%E5%BD%95%E4%BD%9C%E4%B8%BA%E5%8F%AF%E9%80%89%E9%A1%B9%EF%BC%88Ubuntu%2012.04%EF%BC%89.png)
我有一台运行 Ubuntu 12.04 Server 的服务器。我希望能够使用 DSA 密钥在命令行上使用 SFTP,这样我就不必在终端中输入密码。这可以在相同的服务器...例如,我想通过 SFTP 连接到本地主机(在运行之前测试一些 PHP 代码)。但我仍然希望允许其他客户端使用密码登录(如果他们愿意的话)。我不希望证书被强制,但如果证书通过或其他情况,我不希望它要求输入密码。
我在 ssh_config 中启用了以下选项:
RSAAuthentication yes
PasswordAuthentication yes
PubkeyAuthentication yes
IdentityFile ~/.ssh/id_dsa
以下具有所示权限的文件位于 /root/.ssh/ 中
-rw-r--r-- 1 root root 668 Apr 10 11:06 authorized_keys
-rw------- 1 root root 668 Apr 10 11:03 id_dsa
-rw-r--r-- 1 root root 608 Apr 10 11:03 id_dsa.pub
我使用以下命令将密钥复制到授权密钥中:
cat /root/.ssh/id_dsa.pub >> /root/.ssh/authorized_keys
当我 cat 授权密钥时,它已经添加了密钥。
因此,当我尝试使用 sftp 连接时sftp -v root@testserver
(仅在本地,再次用于测试一些代码,但这并不重要),我仍然会收到密码提示。以下是详细输出的一部分:
debug1: Authentications that can continue: publickey,password
debug1: Next authentication method: publickey
debug1: Trying private key: /root/.ssh/id_rsa
debug1: Offering DSA public key: /root/.ssh/id_dsa
debug1: Authentications that can continue: publickey,password
debug1: Trying private key: /root/.ssh/id_ecdsa
debug1: Next authentication method: password
root@testserver's password:
我是不是忽略了某些显而易见的东西?还是说本地连接无法正常工作?
谢谢
答案1
如果在 中设置了 ,则目录中的权限/root/.ssh
是错误的。您可以通过启用、重新启动服务器并查看日志来检查是否是这种情况(对于 Ubuntu,如果您没有更改库存 syslog 配置)StrictModes yes
/etc/ssh/sshd_config
LogLevel DEBUG
/var/log/auth.log
纠正它们发出:
chmod -R go= /root/.ssh
然后再试一次。
同时拥有PubKeyAuthentication
和PasswordAuthentication
可以做你想做的事情,即对于那些提供公钥的用户,他们的访问将是无密码的(前提是他们的公钥存在于文件中authorized_keys
);而那些没有提供公钥的用户将被提示输入密码。
并且RSAAuthentication
仅与协议的第 1 版一起使用,希望您不要使用该版本,因为它不安全。
不要忘记阅读SSHD_CONFIG(5)
手册页。