sudo without password
Some ubuntu server comes with only root account. I recommend create a ubuntu account for everyday use and use sudo to do root jobs. We do not even need to set and remember any password for the ubuntu account, because we normally login this account using the SSH keys file.
create ubuntu account
sudo adduser --gecos "" --disabled-password ubuntu
sudo without password prompt (using command line)
echo "ubuntu ALL=(ALL) NOPASSWD:ALL" | sudo tee /etc/sudoers.d/90-cloud-init-users
sudo chmod 0440 /etc/sudoers.d/90-cloud-init-users
sudo without password prompt (using editor)
sudo vim /etc/sudoers.d/90-cloud-init-users
add the following lines
# User rules for ubuntu
ubuntu ALL=(ALL) NOPASSWD:ALL
sudo chmod 0440 /etc/sudoers.d/90-cloud-init-users
how to switch to another user
sudo -u ubuntu -i
run as another user
sudo -u ubuntu whoami