Ubuntu24.04 安装 ssh 开启 22 端口及允许 root 用户远程登录
1、安装 openssh-server 插件开启 22 端口访问
# 安装ssh会默认启动服务并开启22端口
apt update
apt install openssh-server
2、开启 root 用户远程访问
- 激活 root 用户,设置 root 用户登录密码
hunter@localhost:/$ sudo passwd root
New password:
Retype new password:
- 修改配置
找到配置文件 / etc/ssh/sshd_config,打开注释 #PermitRootLogin prohibit-password,并修改为
PermitRootLogin yes
hunter@hunter-SER:/$ cat /etc/ssh/sshd_config
......
#LoginGraceTime 2m
#PermitRootLogin prohibit-password
PermitRootLogin yes
#StrictModes yes
#MaxAuthTries 6
#MaxSessions 10
......
3、重启 ssh 服务
service ssh restart