设置ssh密码登录
服务器配置与部署

设置ssh密码登录

JACIN··5 分钟阅读

目录#

[[toc]]

设置ssh 密码登录#

python
cp /etc/ssh/sshd_config /etc/ssh/sshd_config.bak

root@DMIT-ekXdcJp4HS:~# cat > /etc/ssh/sshd_config << 'EOF'
Port 2222
PermitRootLogin yes
PasswordAuthentication yes
ChallengeResponseAuthentication yes
UsePAM yes
Subsystem sftp /usr/lib/openssh/sftp-server
EOF
root@DMIT-ekXdcJp4HS:~# 

然后设置密码即可:

python
sudo passwd root


然后重启服务
sudo systemctl restart ssh

安装 fail2ban#

安装 fail2ban

python
sudo apt update
sudo apt install -y fail2ban

不要直接改 jail.conf,而是在 /etc/fail2ban/ 下新建一个 jail.local 覆盖默认设置:

vim /etc/fail2ban/jail.local

python
[DEFAULT]
backend = systemd
bantime  = 3600
findtime = 600
maxretry = 5

[sshd]
enabled = true
port    = 2222
filter  = sshd
python
sudo systemctl restart fail2ban
sudo systemctl enable fail2ban

查看日志

python
sudo fail2ban-client status sshd

遇到这个错误的话:

text
root@s52281 ~ # sudo fail2ban-client status sshd
2026-01-24 07:43:28,808 fail2ban                [145026]: ERROR   NOK: ('sshd',)
Sorry but the jail 'sshd' does not exist

安装服务
root@s52281 ~ # sudo apt install python3-systemd

评论

还没有评论,来发第一个吧