最近在使用STM32MP157开发项目,在配置ssh时,出现上面的错误,经过一番的折腾,算是解决了,在这里做一下记录,以备后续查阅。
我的板子有以下两个前提:
1、文件系统使用了buildroot构建,在构建的过程中,使能了openssh;
2、统的init软件使用了systemd,所以可以使用其相关命令对进程进行操作;
在使用中出现的问题:
1、ssh客户端远程登录板子,出现“connection refused”的错误;
2、在板子上使用/usr/sbin/sshd restart重启sshd,出现“Extra argument restart.”的提示;
解决方法:
1、使用systemctl status sshd 查看sshd服务的运行状况,在异常情况下,会有下面的提示:
[root@fengbo:/]# systemctl status sshd
��● sshd.service - OpenSSH server daemon
Loaded: loaded (/usr/lib/systemd/system/sshd.service; enabled; vendor preset: enabled)
Active: failed (Result: exit-code) since Fri 2020-02-07 15:57:02 UTC; 5min ago
Process: 415 ExecStartPre=/usr/bin/ssh-keygen -A (code=exited, status=0/SUCCESS)
Process: 416 ExecStart=/usr/sbin/sshd -D -e (code=exited, status=255/EXCEPTION)
Main PID: 416 (code=exited, status=255/EXCEPTION)
Feb 07 15:57:02 fengbo systemd[1]: Starting OpenSSH server daemon...
Feb 07 15:57:02 fengbo systemd[1]: Started OpenSSH server daemon.
Feb 07 15:57:02 fengbo sshd[416]: /var/empty must be owned by root and not group or world-writable.
Feb 07 15:57:02 fengbo systemd[1]: sshd.service: Main process exited, code=exited, status=255/EXCEPTION
Feb 07 15:57:02 fengbo systemd[1]: sshd.service: Failed with result 'exit-code'.
2、从上面的提示,可以看出来,sshd服务启动失败,里面有一个重要的提示是“/var/empty must be owned by root and not group or world-writable.”,在开发板上查看这个路径,发现该路径的文件夹属于dbus,这个问题的原因貌似是找到了。
3、根据上面找到的原因,对该路径进行修改:
首先,增加/var/empty/sshd文件夹,mkdir sshd;
其次,修改该路径的拥有者,chown -R root.root /var/empty/sshd;
接着,修改该路径的权限,chmod 744 /var/empty/sshd;
最后,重启sshd服务,systemctl restart sshd,不出意外,会重启成功,使用systemctl status sshd查看sshd运行状态,如下所示:
[root@fengbo:~]# systemctl status sshd
● sshd.service - OpenSSH server daemon
Loaded: loaded (/usr/lib/systemd/system/sshd.service; enabled; vendor preset: enabled)
Active: active (running) since Fri 2020-02-07 15:53:31 UTC; 1h 16min ago
Process: 406 ExecStartPre=/usr/bin/ssh-keygen -A (code=exited, status=0/SUCCESS)
Main PID: 407 (sshd)
Memory: 3.2M
CGroup: /system.slice/sshd.service
├─407 /usr/sbin/sshd -D -e
├─408 sshd: root@pts/0
├─410 -bash
├─480 systemctl status sshd
└─481 /bin/more
Feb 07 15:53:30 fengbo systemd[1]: Starting OpenSSH server daemon...
Feb 07 15:53:31 fengbo systemd[1]: Started OpenSSH server daemon.
Feb 07 15:53:31 fengbo sshd[407]: Server listening on 0.0.0.0 port 22.
Feb 07 15:53:36 fengbo sshd[408]: Accepted password for root from 192.168.30.1 port 46066 ssh2
Feb 07 15:53:55 fengbo sshd[414]: Connection closed by 127.0.0.1 port 47500 [preauth]
这样,就正常运行了,再使用ssh命令远程登录,就可以登录成功了。好了,今天就记录到这里。