使用ssh键登录到RPi比每次键入密码都方便得多。
如果要从自动化脚本登录或使用诸如scp或rsync之类的程序,这将特别方便
那么,如何设置ssh密钥以登录到RPi?
这里的问题/答案非常相似。
—
吉文斯2012年
使用ssh键登录到RPi比每次键入密码都方便得多。
如果要从自动化脚本登录或使用诸如scp或rsync之类的程序,这将特别方便
那么,如何设置ssh密钥以登录到RPi?
Answers:
如果您以前从未听说过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
一旦设置了基于密钥的登录名,就不再需要使用密码登录了。您可以禁用它,这更加安全。
首先,登录到您的树莓派和开放/etc/ssh/sshd_config
的root
; 例如,运行sudo vim /etc/ssh/sshd_config
。
找到包含的行PasswordAuthentication
;它可能显示为#PasswordAuthentication yes
。
更改此行,使其显示为
密码验证否
重新启动Raspberry Pi,或者只是sshd
。
要sshd
在Arch上重新启动,请运行sudo rc.d restart sshd
。
要sshd
在基于Debian的发行版上重新启动,请运行sudo /etc/init.d/sshd restart
。