GNU/Linux Desktop Survival Guide
by Graham Williams |
|||||
SUDO No Password |
20201228 Cloud installations of Ubuntu generally provide for the user created during installation to have sudo access without a password, by default. In fact this user generally does not have a password either. This is convenient for the system administrator and is considered a safe practice when access to the server is limited to using ssh public keys. The user with these privileges (the username created at installation time) will be named in the file /etc/sudoers.d/90-cloud-init-users:
# Created by cloud-init v. 20.1-10-g71782edf-0ubuntu5 on Mon, 17 Aug 2020 04:58:35 +0000 # User rules for kayon kayon ALL=(ALL) NOPASSWD:ALL |
To grant other users this password-less access to sudo, use visudo to add this rule:
$ sudo visudo # User alias specification kt ALL=(ALL) NOPASSWD:ALL |
I've not been able to determine why, but this does not work to allow user kt access without a password. If instead the file /etc/sudoers.d/90-cloud-init-users is edited to replace kayon with kt it does work. Note that on install this file does not have write permission and so that will need to be modified in order to change it. However, there is probably good reason it is not writable.
$ sudo ls -l /etc/sudoers.d/90-cloud-init-users -r--r----- 1 root root 144 Nov 17 09:28 /etc/sudoers.d/90-cloud-init-users $ sudo chmod u+w /etc/sudoers.d/90-cloud-init-users $ sudo editor /etc/sudoers.d/90-cloud-init-users |
Change the username to that of the privileged user, save the file and exit the editor.
The change takes effect immediately so login to that priviledged user's account and continue:
$ sudo chmod u-w /etc/sudoers.d/90-cloud-init-users $ sudo -K |