连接方式:
在树莓派终端查询ip
/sbin/ifconfig
和ssh端口号:
sudo nano /etc/ssh/sshd_config
打开SSH配置文件后,找到以Port开头的行,后面的数字就是SSH端口号,默认为22.
1. 报错1:connection refused
说明树莓派端在SSH服务在启动时不会自动启动,当前未被设置为在系统启动时自动激活,服务当前未运行,检查方式:在终端输入:
bash
sudo systemctl status ssh.service
如果返回的结果中Loaded的状态disabled, Active的状态为inactive,则当前树莓派端的ssh未运行,有两种方法可解决:方法1. 在图形界面找到-首选项-raspberry pi configuration, 在interfaces里打开ssh选项。方法2.在终端输入以下代码
bash
sudo systemctl enable ssh.service
之后可以使用以下命令启动SSH服务
bash
sudo systemctl start ssh.service
树莓派端打开ssh后,仍然无法连接,可在树莓派的终端上查询SSH服务的配置并确认
PermitRootLogin和PasswordAuthentication是否被设置为yes, 查看SSH配置文件方式:
bash
sudo nano /etc/ssh/sshd_config
打开编辑器中,可使用搜索定位到 PermitRootLogin和PasswordAuthentication查看是否被设置为yes, 如果不是的话修改为yes状态。就可通过ssh用密码登录(但不够安全,因为root用户拥有完全的权限)。 在nano中,按ctrl+o保存文件,然后按ctrl+x退出。
之后重启SSH服务,使用以下命令
bash
sudo systemctl restart sshd
报错2: 发现使用putty仍然无法连接,始终提示Can’t agree a key change algorithm,说明putty版本太旧了,可到官网重新下载一个最新版(我的电脑端win使用的):Download PuTTY: latest release (0.81) (引自【踩坑】Putty报错: Can’t agree a key change algorithm_用putty连接树莓派显示 couldn't agree a key exchange-CSDN博客)
输入ip和SSH端口号,提示窗口选择accept, 根据提示输入主机名称和密码,成功登录!