在Linux中,可以通过以下几种方式配置和管理SSH服务器:
- 安装SSH服务器:
- OpenSSH:sudo apt install openssh-server
例如:
# 安装OpenSSH服务器
sudo apt install openssh-server
- 配置SSH服务器:
- 编辑
/etc/ssh/sshd_config
配置文件,设置允许的用户.端口号.登录方式等。
例如:
# /etc/ssh/sshd_config
Port 22222 # 设置SSH端口为22222
PermitRootLogin no # 禁止root远程登录
PasswordAuthentication yes # 允许密码认证
- 管理SSH服务器:
- 使用
systemctl
管理ssh
服务。 - 使用
ssh-keygen
生成SSH密钥。 - 使用
ssh-copy-id
拷贝SSH密钥到客户端。
例如:
# 启动ssh服务
sudo systemctl start ssh
# 停止ssh服务
sudo systemctl stop ssh
# 生成SSH密钥
ssh-keygen -t rsa -b 4096 -C "your_email@example.com"
# 拷贝SSH密钥到客户端
ssh-copy-id user@192.168.1.100
- 测试SSH服务器:
- Windows下使用PuTTY工具连接SSH。
- Mac/Linux下使用命令
ssh user@host
连接SSH。 - 连接示例: 主机:192.168.1.100 端口:22222 用户名:user