如何设置ssh密钥以登录到我的RPi


Answers:


16

的Linux

如果您以前从未听说过ssh键,则需要生成一个这样的键

$ ssh-keygen -t dsa

这将创建一个目录~/.ssh/并存储密钥文件

$ ls -l .ssh/
-rw------- 1 gnibbler gnibbler 668 Aug 22  2004 .ssh/id_dsa
-rw------- 1 gnibbler gnibbler 603 Aug 22  2004 .ssh/id_dsa.pub

您需要复制id_dsa.pub到RPi。有一种使用帮助程序脚本执行此操作的简单方法。

$ ssh-copy-id -i ~/.ssh/id_dsa.pub pi@raspberrypi.local

您需要pi最后一次输入用户密码

下次登录时,不会提示您输入密码

$ ssh pi@raspberrypi.local
Linux raspberrypi 3.1.9+ #174 PREEMPT Sun Jul 22 19:04:28 BST 2012 armv6l

The programs included with the Debian GNU/Linux system are free software;
the exact distribution terms for each program are described in the
individual files in /usr/share/doc/*/copyright.

Debian GNU/Linux comes with ABSOLUTELY NO WARRANTY, to the extent
permitted by applicable law.

Type 'startx' to launch a graphical session

如何禁用密码登录?

一旦设置了基于密钥的登录名,就不再需要使用密码登录了。您可以禁用它,这更加安全。

  1. 首先,登录到您的树莓派和开放/etc/ssh/sshd_configroot; 例如,运行sudo vim /etc/ssh/sshd_config

  2. 找到包含的行PasswordAuthentication;它可能显示为#PasswordAuthentication yes

  3. 更改此行,使其显示为

    密码验证否

  4. 重新启动Raspberry Pi,或者只是sshd

Arch Linux

sshd在Arch上重新启动,请运行sudo rc.d restart sshd

Debian /树莓派

sshd在基于Debian的发行版上重新启动,请运行sudo /etc/init.d/sshd restart


请注意,仅在您知道连接已经安全的情况下才应使用无密码ssh 。否则,您将面临节省10秒的风险。
吉文斯

@Jivings解释吗?密钥始终比密码更安全。
亚历克斯·张伯伦

@gnibbler您接受有关如何禁用密码登录的编辑吗?
亚历克斯·张伯伦

@AlexChamberlain,当然
约翰·拉·

@AlexChamberlain此答案说明如何设置无密码的密钥。那就是我所说的
Jivings
By using our site, you acknowledge that you have read and understand our Cookie Policy and Privacy Policy.
Licensed under cc by-sa 3.0 with attribution required.