设置 SSH 服务器
概述
本文简要概述了 Alpine Linux 上的 SSH。
另请参阅 Secure Shell (Wikipedia)。
OpenSSH
OpenSSH 是一种流行的 SSH 实现,用于远程加密登录到机器。OpenSSH 将 sshd 定义为守护进程,将 ssh 定义为客户端程序。
openssh
软件包在 Alpine Linux 上提供 OpenSSH。
安装
安装 openssh
软件包
apk add openssh
acf-openssh
(假设您有 setup-acf 脚本)。另请参阅 Alpine Linux 软件包管理。
服务命令
启用 sshd 服务,以便它在启动时启动
rc-update add sshd
列出服务以验证 sshd 是否已启用
rc-status
立即启动 sshd 服务并创建配置文件
rc-service sshd start
lbu ci
命令保存您的设置。请参阅 Alpine 本地备份。另请参阅 Alpine Linux Init 系统。
微调
您可能希望更改默认配置。本节描述了一些配置选项作为示例,但这绝不是一个详尽的列表。有关完整详细信息,请参阅手册。
微调通过编辑 /etc/ssh/sshd_config
完成。任何以“#”开头的行都会被 sshd 忽略。
UseDNS no # By setting this to no, connection speed can increase. PasswordAuthentication no # Do not allow password authentication.
其他配置选项在 etc/ssh/sshd_config
中显示。该文件包含注释,解释了许多选项。
防火墙和端口更改
默认情况下,sshd 将在 TCP 端口 22 上通信。
有时 22/tcp 会被您无法控制的防火墙阻止。在这种情况下,将 Port 选项更改为 /etc/ssh/sshd_config
中未使用的端口号可能很有用。
Port 443 # Use whichever port number fits your needs
在修改配置文件后重启 sshd
rc-service sshd restart
lbu ci
命令保存您的设置。请参阅 Alpine 本地备份。Dropbear
Dropbear 是 OpenSSH 的轻量级 SSH 客户端/服务器替代方案。
服务器
~/.ssh/authorized_keys
可以通过 Alpine setup scripts 安装 dropbear
,或者手动使用
apk add dropbear
启动它
rc-service dropbear start
将其添加到默认运行级别
rc-update add dropbear
使用以下命令检查所有可用的服务器选项
dropbear -h
配置文件位于 /etc/conf.d/dropbear
DROPBEAR_OPTS="-w -s"
将禁止 root 登录和密码登录客户端
dropbear-dbclient
包含 SSH 客户端,可以手动安装
apk add dropbear-dbclient
在其最简单的形式中,它可以这样使用
dbclient <user>@host.example.com
dbclient host.example.com
dbclient x.x.x.x
(其中 x.x.x.x 是远程机器的 IP 地址)。
使用 dbclient -h
查看所有可用的选项。