sudo and non sudo in one command
I need to be able to run the command
Code:
rsync -a --delete ~/Music /SDcard && shutdown because that would make all the files that rsync copies owned by root. I need to be able to run this command because syncing my music library takes a while and that means I also won't be around to type in my sudo password anyway. Any ideas or suggestions? Thanks. |
That's what sudo was invented for. Give a group you're in access to the shutdown command without password.
"man sudoers". |
&& sudo shutdown
|
echo 'yourusername ALL=(root) NOPASSWD: /usr/sbin/shutdown' >> /etc/sudoers
and rsync -a --delete ~/Music /SDcard && sudo shutdown |
pan64 - that command would be waiting for a password and I would be around to enter it. That's actually what I tried.
schedar - I'll give that a try. Does it matter that there is no file called /usr/sbin/shutdown? When I ran `which shutdown` it returned /sbin/shutdown. Should I replace /usr/sbin/shutdown with /sbin/shutdown in your examples? Thanks all. |
Yes replace path with the valid one.
|
garrett@mint-desktop /sbin $ sudo echo 'garrett ALL=(root) NOPASSWD: /sbin/shutdown' >> /etc/sudoers
bash: /etc/sudoers: Permission denied |
you should try sudo visudo instead (and add the line: 'garrett ALL=(root) NOPASSWD: /sbin/shutdown). That will skip password checking
|
Use visudo command to edit the sudoers file rather than editing it directly or echoing stuff into it.
edit: SNAP! :) |
#
# 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" # Host alias specification # User alias specification # Cmnd alias specification # User privilege specification root 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 garrett ALL=(root) NOPASSWD: /sbin/shutdown It's still not working, I'm still getting the error that I need to be root. |
Here's a nice page on how to shutdown as a regular user...
http://www.spencerstirling.com/compu.../shutdown.html |
Thanks JaseP - That got it.
|
All times are GMT -5. The time now is 05:45 AM. |