目录
第一部分:安装和配置 SSH 服务

1. 安装 OpenSSH 包
使用以下命令安装 OpenSSH 软件包:
tce-load -wi openssh
2. 使用模板创建 SSH 配置文件
使用以下命令将示例配置文件复制到 sshd_config
文件中:
sudo cp /usr/local/etc/ssh/sshd_config.orig /usr/local/etc/ssh/sshd_config
注意:原文说明的是将 ssh_config.example
和 sshd_config.example
分别复制到 ssh_config
和 sshd_config
,但我发现实际文件是 ssh_config.orig
和 sshd_config.orig
。不过具体操作是一样的,并且实际上复制 sshd_config.example
就可以运行了,所以可以根据实际情况自行修改命令。
3. 启动 SSH 服务
使用以下命令启动 SSH 服务:
sudo /usr/local/etc/init.d/openssh start
4. 更改默认用户 "tc" 的密码
更改默认用户 "tc" 的密码,以便您可以在 SSH 登录提示框下输入此密码。使用以下命令以更改密码:
echo tc:password | sudo chpasswd
注意:如果要更改 root 密码,可以使用以下命令以更改 root 密码:
echo root:password | sudo chpasswd
5. 检查 IP 地址
确保您的 TinyCore Linux 系统有正确的 IP 地址。使用以下命令检查 IP 地址:
ifconfig -a
6. 验证 SSH 服务
确保 SSH 服务正在监听端口 22。使用以下命令检查:
netstat -tuln | grep 22
或者使用 ss
命令:
ss -tuln | grep 22
7. 使用 SSH 客户端
从另一台机器上使用 SSH 客户端连接到您的 TinyCore Linux 系统,确保一切正常。例如:
ssh tc@your_tinycore_ip
第二部分:使 SSH 配置持久化
1. 编辑启动文件
为了让 SSH 服务在系统启动时自动启动,可以将其添加到 /opt/bootsync.sh
脚本中。
-
编辑
/opt/bootsync.sh
:nano /opt/bootsync.sh
-
添加启动命令:
在文件末尾添加以下行:
/usr/local/etc/init.d/openssh start
-
保存并退出:
按
Ctrl+X
,然后按Y
确认保存,最后按Enter
退出编辑器。
2. 编辑 .filetool.lst
文件
为了确保配置文件在系统重启后仍然有效,需要将这些文件添加到 .filetool.lst
文件中。
-
编辑
.filetool.lst
:nano ~/.filetool.lst
-
添加配置文件路径:
在文件中添加以下路径:
/usr/local/etc/ssh/sshd_config
-
保存并退出:
按
Ctrl+X
,然后按Y
确认保存,最后按Enter
退出编辑器。
3. 备份 .filetool.lst
文件中定义的配置
使用以下命令备份 .filetool.lst
文件中定义的配置:
filetool.sh -b
第三部分:自动化安装脚本
为了简化安装和配置过程,可以编写一个自动化安装脚本。以下是一个示例脚本:
#!/bin/sh
# 安装 OpenSSH 包
tce-load -wi openssh
# 创建 SSH 配置文件
sudo cp /usr/local/etc/ssh/sshd_config.orig /usr/local/etc/ssh/sshd_config
# 启动 SSH 服务
sudo /usr/local/etc/init.d/openssh start
# 更改默认用户 "tc" 的密码
echo tc:password | sudo chpasswd
# 更改 root 密码
echo root:password | sudo chpasswd
# 检查 IP 地址
ifconfig -a
# 验证 SSH 服务
netstat -tuln | grep 22
# 编辑启动文件
echo "/usr/local/etc/init.d/openssh start" >> /opt/bootsync.sh
# 编辑 .filetool.lst 文件
echo "/usr/local/etc/ssh/sshd_config" >> ~/.filetool.lst
# 备份配置文件
filetool.sh -b
将上述脚本保存为 install_ssh.sh
,然后运行:
chmod +x install_ssh.sh
./install_ssh.sh