3

If I try using sudo as a non-privileged user, I get a message that the user is not in the sudoers file. I know the Administrator password, but I do not know, how to use it from a non-privileged (Standard) user.

muru
  • 197,895
  • 55
  • 485
  • 740
Tomáš Pečený
  • 1,407
  • 7
  • 19
  • 45

2 Answers2

5

Use pkexec instead. If the current user doesn't have privileges, or if there are multiple users who can authorize an action, it will prompt you to select the user:

$ pkexec true              
==== AUTHENTICATING FOR org.freedesktop.policykit.exec ===
Authentication is needed to run `/bin/true' as the super user
Multiple identities can be used for authentication:
 1.  muru
 2.  sysad, (sysad)
Choose identity to authenticate as (1-2): 1
Password:

pkexec, of course, does not follow the sudo configuration, but its own. However, if you added admin users by adding them to the sudo group, they will also be granted Polkit admin rights by Ubuntu's default configuration.

muru
  • 197,895
  • 55
  • 485
  • 740
  • Is this implemented on all currently supported Ubuntus or only a certain version and later? (Because that's relevant, if only 'cause it's tagged 12.04) – Thomas Ward Jun 26 '15 at 02:13
  • I don't have a 12.04 system around to check, but AFAIK, Polkit came along before 12.04. For example, see this question from 2011: http://askubuntu.com/q/78352/158442. – muru Jun 26 '15 at 02:17
  • I am not sure how to configure the pkexec eg. for hibernating , see http://askubuntu.com/questions/641238/how-to-hibernate-from-a-non-privileged-user. A related discussion is http://chat.stackexchange.com/rooms/25226/discussion-between-tomas-peceny-and-thomas-w .Thanks! – Tomáš Pečený Jun 26 '15 at 11:58
  • Unfortunately with pkexec I don't see command output in the terminal. – gmk57 Dec 20 '21 at 17:34
3

To go from a nonprivileged user to a sudo user, you do not use sudo.

Instead, you first have to switch users.

Login as the other user with the following command from nosudo user (assuming nosudo is the nonprivileged user, yessudo is the sudoer):

su - yessudo

It will then prompt for the login password for yessudo. After you login as yessudo you can run sudo commands from that user. If at any time you exit out of that and return to the nosudo user, you have to do the command above again.

Thomas Ward
  • 74,764
  • Note that this does not solve the problem of you not being in sudoers. Also consider that it's probably that way for a reason, so you should reconsider the ramifications of going about this method. – Thomas Ward Jun 26 '15 at 02:09
  • 1
    @ Thomas W.: Yes, I care for security and I will always switch back to the 'nosudo' user. I understand that the system cannot switch it back straight automatically . – Tomáš Pečený Jun 26 '15 at 02:51
  • @ Thomas W.: Is it not possible to enable using sudo from the standard user by adding somehow the standard user into a sudoers file? Thanks! – Tomáš Pečený Jun 26 '15 at 03:16
  • @TomasPeceny yes, but at that point the user becomes a privileged user, and not a standard user. Add the unprivileged user to the sudo group, and they'll have sudo access (usermod -a -G sudo nosudo is the command, where nosudo is the non-sudoers user from above). Then, nosudo user should log out and log back in, thereby refreshing their groups membership. (HOWEVER, while this would do what you achieve and give sudo access to the nosudo user, pkexec would be a better option if you want to keep nosudo as an unprivileged user) – Thomas Ward Jun 26 '15 at 03:23
  • @ Thomas W.: I see I have misunderstood the term 'sudoer'. I seek for a method how to shorten the time when I am connected to the network as the privileged user. As far as possible without complicated configuring. Your answer appears to be really the proper solution for me. Thanks! – Tomáš Pečený Jun 26 '15 at 03:43
  • @ Thomas W.: But the 'sudo pm-hibernate' does not work this way (the CPU is working further, after a notice 'cannot find...'). Do you have an idea how to hibernate from a non-privileged user? Suspending works OK. – Tomáš Pečený Jun 26 '15 at 04:05
  • @TomasPeceny Hibernate doesn't work in all systems. And I believe that's why they disable it. You have to add your own user to the sudo group then execute with sudo. Or use pkexec. – Thomas Ward Jun 26 '15 at 11:27