- # 查看我的 Ubuntu 版本(安装到VMvare)
wc@ubuntu:~/Desktop$ sudo The program 'sudo' can be found in the following packages: * sudo * sudo-ldap Try: sudo apt install <selected package>
- # 不小心把 /usr/bin/sudo/ 删了,普通用户赋权sudo失败
wc@ubuntu:~$ uname -a Linux 我的用户名 4.13.0-43-generic #48~16.04.1-Ubuntu SMP Thu May 17 12:56:46 UTC 2018 x86_64 x86_64 x86_64 GNU/Linux
- # 进入 root用户 ,输入密码,如果忘记密码,下方有重新设置的方法
# 如果忘了 root 密码,可以重新设置,设置方法在最下方; 如果知道密码,跳过这一步.wc@ubuntu:~/Desktop$ su -l root Password: # 密码正确的话进入下一步
- # 安装 sudo ,会提示 sudo 已存在,安装失败
root@ubuntu:~# apt install sudo Reading package lists... Done Building dependency tree Reading state information... Done sudo is already the newest version (1.8.16-0ubuntu1.5). The following packages were automatically installed and are no longer required: libtool-bin linux-headers-4.13.0-36 linux-headers-4.13.0-36-generic linux-image-4.13.0-36-generic linux-image-extra-4.13.0-36-generic Use 'apt autoremove' to remove them. 0 upgraded, 0 newly installed, 0 to remove and 19 not upgraded
- # 把从别人正常 Ubuntu 系统目录 /usr/bin/ 拷贝的 sudo 复制到 你的 /usr/bin/sudo, 如果不进入 root 用户下,没有复制的权限
root@ubuntu:~# cp /home/wc/Desktop/python1803/sudo /usr/bin/ root@ubuntu:~# sudo usage: sudo -h | -K | -k | -V usage: sudo -v [-AknS] [-g group] [-h host] [-p prompt] [-u user] usage: sudo -l [-AknS] [-g group] [-h host] [-p prompt] [-U user] [-u user] [command] usage: sudo [-AbEHknPS] [-r role] [-t type] [-C num] [-g group] [-h host] [-p prompt] [-u user] [VAR=value] [-i|-s] [<command>] usage: sudo -e [-AknS] [-r role] [-t type] [-C num] [-g group] [-h host] [-p prompt] [-u user] file ...
- # 虽然成功了,但是在普通用户下还是没有权限
root@ubuntu:~# su -l wc
wc@ubuntu:~$ sudo -su: /usr/bin/sudo: Permission denied
- # 赋给 sudo 权限,但是在普通用户下运行还是出错
wc@ubuntu::~$ sudo sudo: /usr/bin/sudo must be owned by uid 0 and have the setuid bit set
- # 还进入到 root ,重新赋权限
root@ubuntu:~# chown root:root /usr/bin/sudo && chmod 4755 /usr/bin/sudo
- # 普通用户下运行成功!!!
wc@ubuntu::~$ sudo usage: sudo -h | -K | -k | -V usage: sudo -v [-AknS] [-g group] [-h host] [-p prompt] [-u user] usage: sudo -l [-AknS] [-g group] [-h host] [-p prompt] [-U user] [-u user] [command] usage: sudo [-AbEHknPS] [-r role] [-t type] [-C num] [-g group] [-h host] [-p prompt] [-u user] [VAR=value] [-i|-s] [<command>] usage: sudo -e [-AknS] [-r role] [-t type] [-C num] [-g group] [-h host] [-p prompt] [-u user] file ...
重新设置 root 的密码
1, 登陆 root 客户端,就是 Ubuntu 的 recovery 模式
开机时按长按 shift 键,进入 grub 菜单,选择第二行 Ubuntu 高级选项(advanced),回车
2, 上下键选择第二行 recovery mode,然后按 'e' 来编辑启动项
3, 修改倒数第三个的内容,倒数第一行是 initrd,上一行是echo,上一项中找到 ro recovery nomodeset ...直到echo,这些内容删掉,然后添加 rw single init=/bin/bash
4, 修改完后,按Ctrl+x 或者 F10 进入单用户模式
5, 下面可以输入命令
想要修改普通用户密码的话输入:passwd 用户名 =>回车 确认2次密码
想要修改root用户密码的话输入: passwd =>回车 确认2次密码(不输入用户名,默认为root)
重启Ubuntu系统.