2015/11/30

Linux change user as sudo root privileges and using command without password

Everytime, if we would like use system command as sudoer, we should input password. But I found a way which using system command without password after google.

Add a new user to the “sudo” group.

Add a new user to the “sudo” group. The change will take effect the next time the user logs in. If you have an existing user, you could pass it.
$ sudo adduser <username> sudo
In my case.
root@jose-desktop:~$ sudo adduser jose sudo

Grant sudo privileges to an existing user.

$ sudo usermod -a -G sudo <username>
In my case.
jose@jose-desktop:~$ sudo usermod -aG sudo jose

Add NOPASSWD:ALL into id setting.

$ sudo su -
$ echo "<username> ALL = (root) NOPASSWD:ALL" | tee /etc/sudoers.d/<username>

In my case.
jose@jose-desktop:~$ sudo su -
root@jose-desktop:~$ echo "jose ALL = (root) NOPASSWD:ALL" | tee /etc/sudoers.d/jose


Change file attributes as root privileges

$ chmod 0440 /etc/sudoers.d/<username>
$ exit

In my case.
root@jose-desktop:~$ chmod 0440 /etc/sudoers.d/jose
root@jose-desktop:~$ exit
jose@jose-desktop:~$


沒有留言:

張貼留言