Monday, 5 December 2011

How to setup a user to login as another user without giving password & root privileges

To login as another user we either need to have root access or need to know his password, but in my case  i don't have both, so i searched for how to set up a non root user to login as another user without knowing their password and below setup solves the purpose,

[madhu@localhost ~]$ su - user1
su: incorrect password

Ah! i entered my password but su expects user1  password  which i am not aware of, ok let me try another way,
[madhu@localhost ~]$ sudo su - user1
Sorry, user user1 is not allowed to execute '/bin/su - user1' as root on localhost.

Ah, i don't have root access

Here's is the setup, add the below entry in /etc/sudoers file, obviously you need root access to edit this file

madhu ALL=(user1) ALL

# user madhu can run any command in any terminal as user1

[madhu@localhost ~]$ sudo -u user1 -i     ##execute the command -i (login shell) as user1
Password:     #enter password of user "madhu"
-bash-3.2$ whoami

That's it now you can allow access to other users to login in to your account without revealing the password.

No comments:

Post a Comment