1

I have installed two vagrant hosts on my machine. I login using user/pass: vagrant/vagrant Created a user user1.

When I am in vagrant user and type below command :

[vagrant@host1]sudo su -

I am able to login to root without specifying a password. Also when I type the command :

[vagrant@host1]sudo su - user1

I get switched to user1. But when I do the same thing with user1 account it ask for user1 password before switching. Why is it so?

3

Because Vagrant by default edits the sudoers file to give itself sudo privileges without requiring a password.

Look at the file /etc/sudoers.d/vagrant and you'll see a line like:

vagrant ALL=(ALL) NOPASSWD:ALL

You can give your user1 the same privileges by doing sudoedit /etc/sudoers and adding the line:

user1 ALL=(ALL) NOPASSWD:ALL

Note: you must use the sudoedit commands, it runs verifications before saving the file to ensure you don't get locked out of your system.

0

My Ubuntu setup

sudo adduser username
sudo adduser username sudo
printf "username ALL=(ALL) NOPASSWD:ALL" > username.tmp
sudo mv username.tmp /etc/sudoers.d/username
sudo chown -R root:root /etc/sudoers.d/username
sudo chmod 664 /etc/sudoers.d/username

this will create a user 'username' who can use sudo without beeing ask for a password.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.