在使用debian9.X系列系统中会经常使用到root用户权限,在执行一些命令或者修改系统配置的时候普通用户是没办法操作的这时候我们就需要开启root权限来操作,然后在使用中频繁切换root有会比较麻烦,在此笔戈整理了debian9系统下如何开启root登录的方法以供各位参考。
切换root权限
su
输入su接着输入root用户密码 成功切换到root用户
kk@kk-48:~$ su
Password:
root@kk-48:/home/kk#
修改SSH配置
修改SSH配置文件启用root用户密码登录 这里推荐使用nano编辑器
nano /etc/ssh/sshd_config
root@kk-48:/home/kk# nano /etc/ssh/sshd_config
GNU nano 2.7.4 File: /etc/ssh/sshd_config
#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 prohibit-password #修改此处配置为 PermitRootLogin yes
#StrictModes yes
#MaxAuthTries 6
#MaxSessions 10
#PubkeyAuthentication yes
# Expect .ssh/authorized_keys2 to be disregarded by default in future.
#AuthorizedKeysFile .ssh/authorized_keys .ssh/authorized_keys2
#AuthorizedPrincipalsFile none
#AuthorizedKeysCommand none
#AuthorizedKeysCommandUser nobody
# For this to work you will also need host keys in /etc/ssh/ssh_known_hosts
^G Get Help ^O Write Out ^W Where Is ^K Cut Text ^J Justify ^C Cur Pos
^X Exit ^R Read File ^\ Replace ^U Uncut Text ^T To Spell ^_ Go To Line
需要修改的地方 找到 #PermitRootLogin prohibit-password 修改其为 PermitRootLogin yes 注意要删除掉前面的#号
以下是修改好的配置文件
#LoginGraceTime 2m
PermitRootLogin yes
#StrictModes yes
#MaxAuthTries 6
#MaxSessions 10
最后保存提交即可 nano编辑保存文件 ctrl+x 接着按 y 确认即可
重启SSH服务
修改好配置文件以后重启SSH服务即可
/etc/init.d/ssh restart
root@kk-48:/home/kk# /etc/init.d/ssh restart
[ ok ] Restarting ssh (via systemctl): ssh.service.
root@kk-48:/home/kk#
最后使用SSH工具验证root登录是否生效 以上即Debian 9允许root用户登录和以ssh方式登录的教程