添加 ssh程
This commit is contained in:
29
ssh程
Normal file
29
ssh程
Normal file
@@ -0,0 +1,29 @@
|
||||
#!/bin/bash
|
||||
|
||||
# 1. 备份原始配置,防止改错
|
||||
sudo cp /etc/ssh/sshd_config /etc/ssh/sshd_config.bak
|
||||
echo "已备份原始配置到 /etc/ssh/sshd_config.bak"
|
||||
|
||||
# 2. 修改 ListenAddress 确保监听所有接口 (0.0.0.0)
|
||||
# 这一步解决“只能局域网连,外部连不上”的监听问题
|
||||
sudo sed -i 's/^#ListenAddress 0.0.0.0/ListenAddress 0.0.0.0/' /etc/ssh/sshd_config
|
||||
sudo sed -i 's/^ListenAddress ::/#ListenAddress ::/' /etc/ssh/sshd_config
|
||||
|
||||
# 3. 允许密码登录 (确保没有被禁用)
|
||||
sudo sed -i 's/^PasswordAuthentication no/PasswordAuthentication yes/' /etc/ssh/sshd_config
|
||||
sudo sed -i 's/^#PasswordAuthentication yes/PasswordAuthentication yes/' /etc/ssh/sshd_config
|
||||
|
||||
# 4. 允许 Root 登录 (可选,视你的安全需求而定)
|
||||
# 如果你需要远程用 root 登录,请取消下面这行的注释
|
||||
# sudo sed -i 's/^#PermitRootLogin.*/PermitRootLogin yes/' /etc/ssh/sshd_config
|
||||
|
||||
# 5. 检查配置文件语法是否正确
|
||||
sudo sshd -t
|
||||
if [ $? -eq 0 ]; then
|
||||
echo "配置检查通过,正在重启 SSH 服务..."
|
||||
sudo systemctl restart ssh
|
||||
echo "修复完成!现在 SSH 应该可以接收来自所有接口的连接了。"
|
||||
else
|
||||
echo "配置文件修改有误,请检查!"
|
||||
exit 1
|
||||
fi
|
||||
Reference in New Issue
Block a user