SSH命令
Raspberry Pi 经过装系统、查ip,就可以通过ssh命令来连接(默认用户名:pi,默认密码:raspberry)
ssh pi@your_pi_ip_addr
新版系统默认关闭SSH
如果安装的是新版的Raspbian系统,默认关闭了ssh,此时ssh连接会报以下错误
ssh: connect to host your_pi_ip_addr port 22: Connection refused
开启SSH
在SD卡根目录(boot)里创建一个名为“ssh”(不要后缀)的文件,然后重启Raspberry Pi,就会自动开启ssh
host key问题
遇到问题
如果是重新装了Raspbian系统,可能会遇到以下问题
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
@ WARNING: REMOTE HOST IDENTIFICATION HAS CHANGED! @
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
IT IS POSSIBLE THAT SOMEONE IS DOING SOMETHING NASTY!
Someone could be eavesdropping on you right now (man-in-the-middle attack)!
It is also possible that a host key has just been changed.
The fingerprint for the ECDSA key sent by the remote host is
SHA256:xZ+HbXTOrZ9H/EaB9zoYZUtFX/xV49me0zJImGLLca0.
Please contact your system administrator.
Add correct host key in /Users/jacky/.ssh/known_hosts to get rid of this message.
Offending ECDSA key in /Users/jacky/.ssh/known_hosts:1
ECDSA host key for 10.12.12.115 has changed and you have requested strict checking.
Host key verification failed.
问题分析
意为/Users/jacky/.ssh/known_hosts中保存的Raspberry Pi的host key不匹配(以前电脑ssh过旧系统的Raspberry Pi,已经生成了一个host key,对应Raspberry Pi 的ip地址,如果安装新系统后还是使用原来的ip地址,则会产生验证失败)
解决方法
终端使用如下命令
ssh-keygen -R your_pi_ip_addr
或者
直接进入/Users/jacky/.ssh/known_hosts,找到Raspberry Pi ip地址对应的那一行(根据提示在第一行),删除这一行。重新ssh连接,应该会连接成功,此时会自动在Users/jacky/.ssh/known_hosts中生成新的host key
注:Windows上推荐使用工具 PuTTY