新装系统是sudo命令没有需要自己安装,安装完成后当前普通账号是没有sudo命令权限的,需要设置。
test@testsvr:~/testsvr$ sudo apt update
[sudo] password for test:
test is not in the sudoers file. This incident will be reported.
设置方法
- 切换到root用户
su
- 取消sudores文件的只读状态
chmod u+w /etc/sudoers
- 编辑sudores分配用户
test
权限,保存退出vi /etc/sudoers
- 撤销sudores文件的修改权限
chmod u-w /etc/sudoers
- 切回当前账号
su test
在sudores增加权限
找到这行 root ALL = (ALL) ALL,在他下面添加xxx ALL=(ALL) ALL (这里的xxx是你的用户名)
# User privilege specification
root ALL=(ALL:ALL) ALL
test ALL=(ALL:ALL) ALL
注: 这是测试机可简单权限处理。如果是正式的,那就需要考虑授权范围。
命令列表
test@testsvr:~/testsvr$ su
Password:
root@testsvr:/home/test/testsvr# chmod u+w /etc/sudoers
root@testsvr:/home/test/testsvr# vim /etc/sudoers
root@testsvr:/home/test/testsvr# chmod u-w /etc/sudoers
root@testsvr:/home/test/testsvr# su test
test@testsvr:~/testsvr$