LinuxQuestions.org
Latest LQ Deal: Complete CCNA, CCNP & Red Hat Certification Training Bundle
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 08-02-2015, 10:35 PM   #1
Garrett85
Member
 
Registered: Jan 2011
Posts: 264

Rep: Reputation: 5
sudo and non sudo in one command


I need to be able to run the command
Code:
rsync -a --delete ~/Music /SDcard && shutdown
The problem is that shutdown is a root or sudo command and I don't want to run rsync as sudo
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.
 
Old 08-02-2015, 11:07 PM   #2
syg00
LQ Veteran
 
Registered: Aug 2003
Location: Australia
Distribution: Lots ...
Posts: 15,959

Rep: Reputation: 2211Reputation: 2211Reputation: 2211Reputation: 2211Reputation: 2211Reputation: 2211Reputation: 2211Reputation: 2211Reputation: 2211Reputation: 2211Reputation: 2211
That's what sudo was invented for. Give a group you're in access to the shutdown command without password.
"man sudoers".
 
Old 08-03-2015, 01:32 AM   #3
pan64
LQ Guru
 
Registered: Mar 2012
Location: Hungary
Distribution: debian/ubuntu/suse ...
Posts: 9,792

Rep: Reputation: 2888Reputation: 2888Reputation: 2888Reputation: 2888Reputation: 2888Reputation: 2888Reputation: 2888Reputation: 2888Reputation: 2888Reputation: 2888Reputation: 2888
&& sudo shutdown
 
Old 08-03-2015, 05:54 PM   #4
schedar
LQ Newbie
 
Registered: Apr 2015
Location: Poland
Distribution: Centos 7
Posts: 16

Rep: Reputation: Disabled
echo 'yourusername ALL=(root) NOPASSWD: /usr/sbin/shutdown' >> /etc/sudoers

and

rsync -a --delete ~/Music /SDcard && sudo shutdown
 
1 members found this post helpful.
Old 08-03-2015, 06:49 PM   #5
Garrett85
Member
 
Registered: Jan 2011
Posts: 264

Original Poster
Rep: Reputation: 5
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.
 
Old 08-03-2015, 07:03 PM   #6
schedar
LQ Newbie
 
Registered: Apr 2015
Location: Poland
Distribution: Centos 7
Posts: 16

Rep: Reputation: Disabled
Yes replace path with the valid one.
 
1 members found this post helpful.
Old 08-03-2015, 10:33 PM   #7
Garrett85
Member
 
Registered: Jan 2011
Posts: 264

Original Poster
Rep: Reputation: 5
garrett@mint-desktop /sbin $ sudo echo 'garrett ALL=(root) NOPASSWD: /sbin/shutdown' >> /etc/sudoers
bash: /etc/sudoers: Permission denied
 
Old 08-04-2015, 03:03 AM   #8
pan64
LQ Guru
 
Registered: Mar 2012
Location: Hungary
Distribution: debian/ubuntu/suse ...
Posts: 9,792

Rep: Reputation: 2888Reputation: 2888Reputation: 2888Reputation: 2888Reputation: 2888Reputation: 2888Reputation: 2888Reputation: 2888Reputation: 2888Reputation: 2888Reputation: 2888
you should try sudo visudo instead (and add the line: 'garrett ALL=(root) NOPASSWD: /sbin/shutdown). That will skip password checking
 
1 members found this post helpful.
Old 08-04-2015, 03:07 AM   #9
descendant_command
Senior Member
 
Registered: Mar 2012
Posts: 1,510

Rep: Reputation: 394Reputation: 394Reputation: 394Reputation: 394
Use visudo command to edit the sudoers file rather than editing it directly or echoing stuff into it.

edit: SNAP!
 
1 members found this post helpful.
Old 08-16-2015, 04:47 PM   #10
Garrett85
Member
 
Registered: Jan 2011
Posts: 264

Original Poster
Rep: Reputation: 5
#
# 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.
 
Old 08-16-2015, 04:52 PM   #11
JaseP
Senior Member
 
Registered: Jun 2002
Location: Eastern PA, USA
Distribution: K/Ubuntu 12.04/14.04, Scientific Linux 6.3/6.4, Android-x86, Pretty much all distros at one point...
Posts: 1,799

Rep: Reputation: 157Reputation: 157
Here's a nice page on how to shutdown as a regular user...
http://www.spencerstirling.com/compu.../shutdown.html
 
1 members found this post helpful.
Old 08-16-2015, 05:40 PM   #12
Garrett85
Member
 
Registered: Jan 2011
Posts: 264

Original Poster
Rep: Reputation: 5
Thanks JaseP - That got it.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Question about the sudo command, specifically how to have sudo act as if user is root slacker_ Linux - Newbie 17 09-22-2013 04:48 PM
LXer: The Ultimate Sudo FAQ To Sudo Or Not To Sudo? LXer Syndicated Linux News 13 04-13-2013 02:36 AM
sudo cd /root gives 'sudo: cd: command not found'. stf92 Linux - Newbie 4 03-03-2012 10:05 AM
(Sudo) command can't run by sudo rahilmaknojia Linux - Server 8 06-25-2010 10:30 AM
sudo mkinitrd -o /boot/initrd.img-2.6.32.9 2.6.32.9 sudo: mkinitrd: command not foun vishwas181 Linux - Newbie 1 02-27-2010 02:16 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 12:48 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration