当 sudo su - 时,我需要为 root 用户设置密码,ubuntu 用户只能通过 ssh 密钥登录。
#ssh -i server.pem [email protected]
[email protected]:~$ sudo su - --> should prompt the password of root
[email protected]:~# --> and also I have setup the password for root, but it does not prompt the password.
[email protected]:/etc/sudoers.d# cat 90-cloud-init-users
# Created by cloud-init v. 0.7.5 on Mon, 12 Sep 2016 10:23:06 +0000
# User rules for ubuntu
ubuntu ALL=(ALL) NOPASSWD:ALL
# User rules for ubuntu
ubuntu ALL=(ALL) NOPASSWD:ALL
# User rules for ubuntu
ubuntu ALL=(ALL) NOPASSWD:ALL
答案1
像这样修改文件ubuntu
中的用户设置:sudoers
ubuntu ALL=(ALL) ALL
当您以用户身份登录ubuntu
并执行时sudo -i
,系统将提示您输入ubuntu
用户的密码。
如果您这样做su
,系统将提示root
您输入密码。