Ubuntu设置root密码并允许root用户使用密码登录

# 设置root密码
root@localhost:~# sudo passwd root
New password: 
Retype new password: 
passwd: password updated successfully

# 设置允许root登录
root@localhost:~# sudo apt install vim
Reading package lists... Done
Building dependency tree... Done
Reading state information... Done
vim is already the newest version (2:8.2.3995-1ubuntu2.15).
0 upgraded, 0 newly installed, 0 to remove and 35 not upgraded
root@localhost:~# vim /etc/ssh/sshd_config

# This is the sshd server system-wide configuration file.  See
# sshd_config(5) for more information.

# This sshd was compiled with PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games

# The strategy used for options in the default sshd_config shipped with
# OpenSSH is to specify options with their default value where
# possible, but leave them commented.  Uncommented options override the
# default value.

Include /etc/ssh/sshd_config.d/*.conf

#Port 22
#AddressFamily any
#ListenAddress 0.0.0.0
#ListenAddress ::

#HostKey /etc/ssh/ssh_host_rsa_key
#HostKey /etc/ssh/ssh_host_ecdsa_key
#HostKey /etc/ssh/ssh_host_ed25519_key

# Ciphers and keying
#RekeyLimit default none

# Logging
#SyslogFacility AUTH
#LogLevel INFO

# Authentication:

#LoginGraceTime 2m
PermitRootLogin yes # 找到该项,将该项的注释取消,值修改为yes
#StrictModes yes
#MaxAuthTries 6
#MaxSessions 10

# 重启sshd服务
root@localhost:~# sudo systemctl restart sshd