问题:我们第一次使用Ubuntu时,默认是没有给sudo权限使用的,首先应该是对sudo进行设置。
sudo的作用:在非root用户使用需要权限的命令时,直接在命令前面加上sudo,就可以获得执行这条命令的权限了。
sudo的配置文件:位于 etc/sudoers,需要root权限进行读写。
操作步骤:
第一次使用无法输入密码时:
book@100ask:~$ pkexec vi /etc/sudoers
然后再输出用户开机密码即可进去配置文件
或者尝试:
book@100ask:~$ sudo visudo
或者
book@100ask:~$ sudo vi /etc/sudoers
进去之后的界面:
#
# This file MUST be edited with the 'visudo' command as root.
#
# Please consider adding local content in /etc/sudoers.d/ instead of
# directly modifying this file.
#
# See the man page for details on how to write a sudoers file.
#
Defaults env_reset
Defaults mail_badpass
Defaults secure_path="/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/snap/bin"
# Host alias specification
# User alias specification
# Cmnd alias specification
# User privilege specification
root ALL=(ALL:ALL) ALL
# Members of the admin group may gain root privileges
%admin ALL=(ALL) ALL
# Allow members of group sudo to execute any command
%sudo ALL=(ALL:ALL) ALL
# See sudoers(5) for more information on "#include" directives:
#includedir /etc/sudoers.d
^G 求助 ^O 写入 ^W 搜索 ^K 剪切文字 ^J 对齐 ^C 游标位置 M-U 撤销 M-A 标记文字 M-] 至括号 M-▲ 上一个 ^B 向后 ^ 前一个字 ^A 顶端
^X 离开 ^R 读档 ^\ 替换 ^U 还原剪切 ^T 拼写检查 ^_ 跳行 M-E 重做 M-6 复制文字 M-W 搜索下一个 M-▼ 下一个 ^F 向前 ^ 后一个字 ^E 尾端
然后需要修改的是:
原来:%sudo ALL=(ALL:ALL) ALL
修改后:%sudo ALL=(ALL:ALL) NOPASSWD:ALL
设置完这个之后基本可以解决无法输入密码的情况了。
另外还有一个方法:
就是将你的操作用户直接设置为root用户,具体的办法:
book@100ask:~$ sudo adduser 用户名 root
执行这条命令之后,你所操作的用户就会变成具有root权限的用户了,使用sudo就不用再输入密码这个步骤了。
谢谢阅读。如有不对的地方,请批评指正。谢谢