开发板网络配置与 SSHD
如果开发板上通过以太网卡与路由器连接,与其他电脑共在同一个网络,可以开启 SSHD 服务,通过远程 ssh 登录,来远程操作系统开发板。
检查开发板上网络
根据 系统配置 章节讲到的网络配置方式来进行网络配置,使用ifconfig
命令查看开发板的IP地址:
root@thead-910:~# ifconfig
eth0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500
inet 192.168.1.100 netmask 255.255.255.0 broadcast 192.168.1.255
inet6 fe80::68af:e8ff:fec6:23ff prefixlen 64 scopeid 0x20<link>
ether 6a:af:e8:c6:23:ff txqueuelen 1000 (Ethernet)
RX packets 2 bytes 410 (410.0 B)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 10 bytes 1040 (1.0 KiB)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
device interrupt 7 base 0xa000
lo: flags=73<UP,LOOPBACK,RUNNING> mtu 65536
inet 127.0.0.1 netmask 255.0.0.0
inet6 ::1 prefixlen 128 scopeid 0x10<host>
loop txqueuelen 1000 (Local Loopback)
RX packets 0 bytes 0 (0.0 B)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 0 bytes 0 (0.0 B)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
可以看到 eth0 网卡的 IP 地址为:192.168.1.100
在HOST 机上通过 ping
命令检查网络是否正常:
ping 192.168.1.100
如果看到类似下面的数据,表示网络正常:
root@thead-910:~# ping 192.168.1.100
PING 192.168.1.100 (192.168.1.100) 56(84) bytes of data.
64 bytes from 192.168.1.100: icmp_seq=1 ttl=64 time=0.723 ms
64 bytes from 192.168.1.100: icmp_seq=2 ttl=64 time=0.486 ms
64 bytes from 192.168.1.100: icmp_seq=3 ttl=64 time=0.493 ms
64 bytes from 192.168.1.100: icmp_seq=4 ttl=64 time=0.514 ms
64 bytes from 192.168.1.100: icmp_seq=5 ttl=64 time=0.498 ms
64 bytes from 192.168.1.100: icmp_seq=6 ttl=64 time=0.492 ms
64 bytes from 192.168.1.100: icmp_seq=7 ttl=64 time=0.498 ms
配置开发板上的 SSH Server
安装 openssh-server
# 安装
apt update
apt install -y ssh openssh-server
配置 sshd_config
# 配置
vi /etc/ssh/sshd_config
# To disable tunneled clear text passwords, change to no here!
PasswordAuthentication yes
#PermitEmptyPasswords no
PermitRootLogin yes
重启 sshd
# 重启 SSH 服务
systemctl restart sshd
SSH 客户端
在主机为 Linux 环境下, sudo apt-get install openssh-client
安装 SSH 客户端。
生成秘钥
root@thead-910:~# ssh-keygen
Generating public/private rsa key pair.
Enter file in which to save the key (/root/.ssh/id_rsa):
Created directory '/root/.ssh'.
Enter passphrase (empty for no passphrase):
Enter same passphrase again:
Your identification has been saved in /root/.ssh/id_rsa
Your public key has been saved in /root/.ssh/id_rsa.pub
The key fingerprint is:
SHA256:Yh1rjgGgVUHmK26d8A6Id2U54enDCd7cI1hg6i/rL6I root@thead-910
The key's randomart image is:
+---[RSA 3072]----+
| oo=. |
| o + |
|. = . . |
| o = = o |
| + o % S |
|.+ * & X |
|o * B X + |
|.oo= o . |
|Eoo=+ |
+----[SHA256]-----+
root@thead-910:~# ls ~/.ssh/
id_rsa id_rsa.pub
- id_rsa 私钥
- id_rsa.pub 公钥
将公钥上传到 ICE 开发板
root@thead-910:~# ssh-copy-id root@192.168.1.100
/usr/bin/ssh-copy-id: INFO: Source of key(s) to be installed: "/root/.ssh/id_rsa.pub"
/usr/bin/ssh-copy-id: INFO: attempting to log in with the new key(s), to filter out any that are already installed
/usr/bin/ssh-copy-id: INFO: 1 key(s) remain to be installed -- if you are prompted now it is to install the new keys
root@192.168.1.100's password: <---------------------- 输入 root 的密码
Number of key(s) added: 1
Now try logging into the machine, with: "ssh 'root@192.168.1.100'"
and check to make sure that only the key(s) you wanted were added.
远程登录
ssh root@192.168.1.100
登录成功后显示信息如下:
Linux thead-910 5.10.4 #2 SMP Sun Jan 3 09:04:16 CST 2021 riscv64
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.
Last login: Tue Jan 12 03:38:48 2021
root@thead-910:~#
上传文件
可以使用 scp
命令将PC 上的文件拷贝到 ICE-EVB 上,也可以将 ICE-EVB 的文件拷贝到 PC上。
上传文件到 ICE-EVB
# 将电脑上的文件拷贝到 ICE-EVB 开发板的 root 账号的 $HOME 目录 (/root) 下:
scp helloworld root@192.168.1.100:~/
从开发板上下载文件
# 将开发板上 root 账号的 $HOME 下的 helloworld 文件下载到电脑上
scp root@192.168.1.100:~/helloworld .
更详细的 ssh
的使用方法,可以通过 http://www.openssh.com 学习。