-1

On the command line, I find that, if I want to administer something, I must first login admin and enter password and then sudo something and enter password again. Is there a way to do this in one step, remembering the password for 60 seconds?

This is not a duplicate. I don't want to make my normal user a suoder.

2

2 Answers 2

2

The passwords used for login and sudo may be the same, but the authentication mechanism behind is it different. So there is no direct way to avoid having to enter the password twice.

Things you can do to overcome this (but with their own drawbacks):

  • Add your current user to /etc/sudoers, so you can use sudo without having to login as another user. You would still need to enter your password whenever you use sudo
  • Enable ssh and add the public key of current user to the authorized ssh keys of the admin user. This allows you to log in as admin with ssh admin@localhost, without entering a password

For the second option, do the following once you've enabled ssh in System Preferences:

  • As your normal user, run ssh-keygen (and just press enter on all questions)
  • Replace ADMIN with the name of the admin user and run

    ssh ADMIN@localhost "mkdir ~/.ssh; cat >> ~/.ssh/authorized_keys" < ~/.ssh/id_rsa.pub
    

    This will be the last time you'll need to enter the password of the admin user to log in

  • Run ssh ADMIN@localhost to log in as the admin user
2
  • If you are sure there is no easy way, thanks. It just occurred to me, though, that one might perhaps be able to do it with a tmux script; but that would require a safe way to store the password temporarily. (Not sure if environment variables would be safe.)
    – Toothrot
    Jan 4, 2016 at 23:57
  • I'm not sure, maybe somebody else has better ideas. The solution above is the one I'm using and it's working fine for me.
    – nohillside
    Jan 5, 2016 at 6:53
-2

Once again open root shell, edit /etc/sudoers using your favourite text editor, and after entry %admin ALL=(ALL) ALL enter yourusername ALL=(ALL) ALL, where yourusername is your Unix-style user name (john or root rather than "John Smith" or "System Administrator").

8
  • 1
    Never ever edit /etc/sudoers directly with your text editor. If you somehow break the file, you will not be able to sudo afterwards, requiring at least a reboot into Single User mode to fix things. From the man page: "The sudoers file should always be edited by the visudo command which locks the file and does grammatical checking. It is imperative that sudoers be free of syntax errors since sudo will not run with a syntactically incorrect sudoers file."
    – nohillside
    Jan 4, 2016 at 18:25
  • @patrix I have done this. My mac works very good
    – Top Sekret
    Jan 4, 2016 at 18:26
  • I didn't say it doesn't work. It's just risky.
    – nohillside
    Jan 4, 2016 at 18:27
  • @patrix If your mac breaks up, it means you have messed up something. My instructions didn't break up anything on my, my brother's and my friend's MacBooks.
    – Top Sekret
    Jan 4, 2016 at 18:28
  • If somebody's "favorite text editor" stores files with DOS line breaks (there are some of those out there) or if somebody makes a typo when entering text in the file, somebody will be stuck.
    – nohillside
    Jan 4, 2016 at 18:32

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .