User account in Ubuntu being refused sudo access
Q My main hard disk is partitioned as a dual boot system - Windows XP on one and Ubuntu on the other. I then added a second hard disk with three FAT32 partitions for data to be shared between the two systems. To use the second disk in Ubuntu, I have to use the System > Admin > Disk Manager at each login to access the FAT32 partitions. Thinking that changing a few file permissions would give me immediate user access to them, I experimented with the group management tools (groupadd, chgrp, usermod as in chapter 14 of Ubuntu Unleashed by Paul and Andrew Hudson, Sams, ISBN 0-672-32909-3).
Unfortunately, the experiment failed for me. I can no longer use sudo - when I try I get a message saying that my user name is not on the sudoers file and my attempt to use it will be reported to Big Brother. In addition the items on the Ubuntu desktop System menus whose use requires root privileges (like Disk Manager and Apt-get) have disappeared. I can get root privileges by booting into the Recovery Mode but I do not know whether the problem can be overcome by editing /etc/sudoers with visudo. The explanation in Ubuntu Unleashed (p294-5) looks risky to me - I am getting too old for this sort of excitement. Perhaps I should reinstall Ubuntu, but that is a blunt instrument - it would be better to solve the problem with a few deft keystrokes. But what does a new installation do? Does it overwrite existing files and destroy the various configuration files? If it inherits the old config files I will be no further forward.
A A new installation will overwrite your system configuration files. Not only the ones you have inadvertently broken, but also the ones that are working perfectly, so it should be a last resort. The problem appears to be that your user is no longer a member of the admin group, probably due to incautious use of usermod, or that the admin group no longer has sudo rights. To check the latter, check that /etc/sudoers contains
%admin ALL=(ALL) ALL
and add it with visudo if not. To see whether you are in the admin group, run id or groups in a terminal, as your normal user. If admin is not listed, you need to boot in Recovery Mode and add yourself to the admin group with
gpasswd -a username admin
Unlike usermod, gpasswd adds groups to your user without affecting your existing groups. To make your FAT partitions available when you boot, you will need to add a line to /etc/fstab for each one.
/dev/hdb1 /mnt/shared1 vfat uid=john,gid=john,u mask=022 0 0
The first three fields should be clear, the device, mount point and filesystem type. The options field is the key: uid and gid set the user and group that will "own" the mounted filesystem, umask sets the permissions (remember that FAT has no concept of owners or permissions). The umask is subtracted from 666 for files and 777 for directories, so this sets files to 644 and directories to 755 (writable by you, readable by everyone). This assumes that your username and group are the same, which is how Ubuntu usually sets things up. If you changed your primary group when fiddling with usermod and friends - id shows your primary group - change it back with
usermod --gid groupname username
substituting the appropriate values for the user and group names. Incidentally, the Big Brother reference only means that the attempt to use sudo will be recorded in the system log file for the administrator to read. You won't be forced to spend three months in a camera-infested house with a dozen strangers who become even more strange by the day, being gawped at on live TV.
Follow us on Identi.ca or Twitter