Add Your Username To Sudo Group And Run Sudo Without Password

First create the user

sudo adduser username

Then add it to the sudo group

usermod -aG sudo yourusername

Then edit the sudoers file. Run:

visudo

and add at the end of the file

yourusername ALL=(ALL) NOPASSWD:ALL

Another option is to allow passwordless sudo for any user in the sudo group.

Replace

# Allow members of group sudo to execute any command
%sudo   ALL=(ALL:ALL) ALL 

with

 # Allow members of group sudo to execute any command, no password
%sudo   ALL=(ALL:ALL) NOPASSWD:ALL 

It might be better to make another file in the /etc/sudoers.d directory. If you have a typo or error of any sort, it will break sudo.

Don't forget to add your key to /home/user/.ssh otherwise you cannot login!

https://linuxize.com/post/how-to-add-user-to-sudoers-in-ubuntu/

https://askubuntu.com/questions/334318/sudoers-file-enable-nopasswd-for-user-all-commands

https://unix.stackexchange.com/a/468423

Then it might be a good idea to disallow root login

Category.Linux