-2

In /etc/sudoers i added:
%myuser ALL=(ALL) NOPASSWD:ALL

Now if i type sudo apt update i don' t need to type the password.
But i want full root permissions: namely, i want to use only apt update.
The apt is an example i want FULL ROOT PERMISSIONS, another example create/modify files everywhere.
I know that i can log in as root (in some OS), but is not to grant root permissions to an user.

I tried to use the root line (root ALL=(ALL:ALL) ALL) in the myuser line but nothing:
%myuser ALL=(ALL:ALL) ALL

This is my /etc/sudoers file:

#
# This file MUST be edited with the 'visudo' command as root.
#
# Please consider adding local content in /etc/sudoers.d/ instead of
# directly modifying this file.
#
# See the man page for details on how to write a sudoers file.
#
Defaults        env_reset
Defaults        mail_badpass
Defaults        secure_path="/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/snap/bin"

# Host alias specification

# User alias specification

# Cmnd alias specification

# User privilege specification
root    ALL=(ALL:ALL) ALL
scorpion  ALL=(ALL:ALL) ALL

# Members of the admin group may gain root privileges
%admin ALL=(ALL) ALL

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

# See sudoers(5) for more information on "#include" directives:

#includedir /etc/sudoers.d

%scorpion ALL=(ALL) NOPASSWD:ALL

I changed the user's UID and GID to 0, but is wrong never do it it will break the user.
Now this is my terminal: I have no name!@my-pc.
I cannot use sudo or su. The root user is not allowed to log in in this system. I' m switching to Debian now i' m on Ubuntu.
I already know how to fix it, log in with CTRL+ALT+F1 and root credentials, then set as before UID and GID.

On Debian initially works but after reboot i can' t login. I cannot change the password passwd: myuser 'myuser' does not exist. So i set as before the UID and GID, i tried to change the password but:

passwd: Authentication token manipulation error
passwd: password unchanged

When i log in i get wrong password.

  • When you start a new shell session, you can just type sudo su - and you will become root and not have to use sudo. – Nasir Riley Sep 27 '18 at 22:31
  • It's bad practice to modify the root line in the sudoers file. Please undo the edit, and see my answer. – eyoung100 Sep 28 '18 at 2:47
6

The more secure way to run apt update with root privileges, without typing sudo apt update, would be to add an alias for apt to your user's profile:

  • alias apt='sudo apt'

Then, whenever you run apt update, or apt upgrade, or apt install <pkg>, the apt command will be run with root privileges. But other commands will just run as your normal user, with normal user privileges.


Now, Acknowledging that there are valid reasons why we don't just run all users with root permissions, the following is a way you can give a user all the same permissions as root, that doesn't use sudo.

  • Change the user's UID and GID to 0 with usermod -ou 0 -g 0 <username>

This will change everything your <username> user does to run with root permissions. Everything.

Yes. I know this is massively insecure. But, it does answer the question.

If you choose this route, please do it on a system you don't mind re-installing from time to time. Running everything as root can end up having unforeseen consequences.

  • 3
    The usermod suggestion is the permanent solution the OP is asking for, hence the upvote. I will expect another question soon on how to recover the system after an accidental oops. – doneal24 Sep 27 '18 at 23:05
  • 1
    Everyone has to learn sometime. When I first started using Linux, I must have reinstalled my system almost daily, from screwing something up. Fixing screwups is really a great way to learn. :) – Tim Kennedy Sep 27 '18 at 23:07
  • 2
    I have told my staff multiple times that you're not a real sysadmin until you have totally destroyed at least one system, often a production server. :) – doneal24 Sep 27 '18 at 23:09
  • hahaha... that's so true! :D – Tim Kennedy Sep 27 '18 at 23:17
  • I already reinstalled the system some times :) now i ' m gonna try the usermod -ou 0 -g 0 <username> change only the UID (as told me before) is a bad idea. The apt is an example i want all root permission, so i can create/modify files everywhere. – Scorpion Sep 28 '18 at 8:12
0

You can type sudo -i, then you get an interactive root shell and don't have to type sudo before each command.

  • I want a permanent solution. – Scorpion Sep 27 '18 at 21:56
  • Then place that command in the user's .profile. Or let the user login as root. – RalfFriedl Sep 27 '18 at 22:01
  • How can i let the user login as root? – Scorpion Sep 27 '18 at 22:08
  • I just set a password for root and can login as root. If your distribution disables root login, you should find out how it is done and undo it. Or at least mention what distribution you are using. – RalfFriedl Sep 27 '18 at 22:17
  • Right, but i don' t want to login as root i want the user to become a "second" root. – Scorpion Sep 27 '18 at 22:22
0

Using Gentoo's /etc/sudoers file as a default, you have two options:

Option 1:


## sudoers file.
.. snip ..
## User privilege specification
##
root ALL=(ALL) ALL
## Add your user here.  This allows you to run all commands as root, 
## not just the update commands.
scorpion ALL=(ALL) ALL
.. snip ..

Option 2:


## sudoers file.
.. snip ..
## User alias specification
##
## Groups of users.  These may consist of user names, uids, Unix groups,
## or netgroups.
# User_Alias    ADMINS = millert, dowdy, mikef
User_Alias  UPDATERS = scorpion
##
## Cmnd alias specification
##
## Groups of commands.  Often used to group related commands together.
# Cmnd_Alias    PROCESSES = /usr/bin/nice, /bin/kill, /usr/bin/renice, \
#               /usr/bin/pkill, /usr/bin/top
# Cmnd_Alias    REBOOT = /sbin/halt, /sbin/reboot, /sbin/poweroff
Cmnd_Alias  UPDATE = /path/to/apt-get, /path/to/apt
.. snip ..
##
## User privilege specification
##
root ALL=(ALL) ALL
UPDATERS ALL=NOPASSWD: UPDATE

Notes

  1. This example assumes your username is scorpion.
  2. I assume the path to all the apt commands are in /sbin but Gentoo doesn't use apt or apt-get so don't forget to edit.
  3. This can be done without adding Command Aliases, and User Aliases, but IMHO, the aliases make it easier to add commands, and to debug if needed.
  • Option is not working is similar to use the root line for my user. Option 2 is for apt only right? i want to grant full root permissions not only apt. – Scorpion Sep 28 '18 at 9:03
  • If you want full permission everywhere then add your user to the sudo group, aka wheel, and remove the comment on the line starting %sudo ALL = ALL... with the nopasswd option. It may read %wheel. You cannot do what your asking, as sudo sets the proper permissions bit, and the UID/GID of 0 should always belong to root as @TimKennedy pointed out. – eyoung100 Sep 28 '18 at 9:41
  • Could you clarify? Yes UID and GID should belong to root, but Tim has only said "Yes. I know this is massively insecure" the problem is that it doens' t work, it will break the user. I removed the comment now i can' t use sudo. Can you post the right configuration? – Scorpion Sep 28 '18 at 10:24
  • i can' t tag you any can you post the right configuration? – Scorpion Oct 2 '18 at 21:17
  • Follow @TimKennedy's answer, and set your UID and GID to zero, thereby replacing the root user with your user. The reason it's "massively insecure" is because you have removed all safety measures. See What's wrong with always being root? Before I can advise you on the proper configuration, should you decide against Tim's answer I need to know what distribution you're using. – eyoung100 Oct 3 '18 at 6:15

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.