LinuxQuestions.org
Review your favorite Linux distribution.
Home Forums Tutorials Articles Register
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 09-30-2016, 05:06 AM   #1
dushyantg
Member
 
Registered: Jun 2016
Posts: 70

Rep: Reputation: Disabled
Create user with having only permission to star/stop service


Hi,

I want to create a user who can only start/stop/restart specific service.

can anyone guide me in that how it can be done?

or a user which can connect over ssh and start/stop/restart specific service.

Last edited by dushyantg; 09-30-2016 at 05:39 AM.
 
Old 09-30-2016, 06:35 AM   #2
Turbocapitalist
LQ Guru
 
Registered: Apr 2005
Distribution: Linux Mint, Devuan, OpenBSD
Posts: 7,295
Blog Entries: 3

Rep: Reputation: 3719Reputation: 3719Reputation: 3719Reputation: 3719Reputation: 3719Reputation: 3719Reputation: 3719Reputation: 3719Reputation: 3719Reputation: 3719Reputation: 3719
Yes, you can do that using "sudo" which is configured in the file /etc/sudoers. Which distro do you have and how do you start, stop, or restart a service normally?

If you use the "service" utility, it could go like this:

Code:
%dushyantg  ALL=(ALL:ALL) /usr/sbin/service apache2 stop, \
           /usr/sbin/service apache2 start, /usr/sbin/service apache2 restart, \
           /usr/sbin/service apache2 reload, /usr/sbin/service apache2 status
That makes the users in the group dushyantg able to stop, start, restart, and reload apache2 as well as see the status.

Be sure to a) use "visudo" for editing /etc/sudoers and b) save but not close /etc/sudoers until you have verified that everything works.

Last edited by Turbocapitalist; 09-30-2016 at 06:36 AM.
 
Old 09-30-2016, 09:32 AM   #3
BW-userx
LQ Guru
 
Registered: Sep 2013
Location: Somewhere in my head.
Distribution: Slackware (15 current), Slack15, Ubuntu studio, MX Linux, FreeBSD 13.1, WIn10
Posts: 10,342

Rep: Reputation: 2242Reputation: 2242Reputation: 2242Reputation: 2242Reputation: 2242Reputation: 2242Reputation: 2242Reputation: 2242Reputation: 2242Reputation: 2242Reputation: 2242
Quote:
Originally Posted by Turbocapitalist View Post
Yes, you can do that using "sudo" which is configured in the file /etc/sudoers. Which distro do you have and how do you start, stop, or restart a service normally?

If you use the "service" utility, it could go like this:

Code:
%dushyantg  ALL=(ALL:ALL) /usr/sbin/service apache2 stop, \
           /usr/sbin/service apache2 start, /usr/sbin/service apache2 restart, \
           /usr/sbin/service apache2 reload, /usr/sbin/service apache2 status
That makes the users in the group dushyantg able to stop, start, restart, and reload apache2 as well as see the status.

Be sure to a) use "visudo" for editing /etc/sudoers and b) save but not close /etc/sudoers until you have verified that everything works.
BIG Q 2 U ~

why do I see that got a use visudo to edit sudoers file? I use nano whenever I edit sudoers file and have had no ill effects as a result of it, so why do I read and even see you stating that got a use visudo to edit said file?
 
Old 09-30-2016, 09:40 AM   #4
Emerson
LQ Sage
 
Registered: Nov 2004
Location: Saint Amant, Acadiana
Distribution: Gentoo ~amd64
Posts: 7,661

Rep: Reputation: Disabled
man visudo tells what are the advantages of visudo over regular editor.
 
Old 09-30-2016, 10:20 AM   #5
Turbocapitalist
LQ Guru
 
Registered: Apr 2005
Distribution: Linux Mint, Devuan, OpenBSD
Posts: 7,295
Blog Entries: 3

Rep: Reputation: 3719Reputation: 3719Reputation: 3719Reputation: 3719Reputation: 3719Reputation: 3719Reputation: 3719Reputation: 3719Reputation: 3719Reputation: 3719Reputation: 3719
Quote:
Originally Posted by BW-userx View Post
BIG Q 2 U ~

why do I see that got a use visudo to edit sudoers file? I use nano whenever I edit sudoers file and have had no ill effects as a result of it, so why do I read and even see you stating that got a use visudo to edit said file?
As Emerson writes the manual page for "visudo" covers a lot of that, but the gist is that it checks syntax. That's better than nothing. You can still lock yourself out even with correct syntax if you tell it to.

If you use "nano" be sure to fire it up with the -w option or even add nowrap to .nanorc so it is done automatically. Some distros will ask you the first time you fire up "visudo" if you want to use "nano" for the editor and set it as the default. Otherwise, you can be sure that the $EDITOR environment variable is set to "nano" and "visudo" will use it then.
 
Old 09-30-2016, 10:48 AM   #6
BW-userx
LQ Guru
 
Registered: Sep 2013
Location: Somewhere in my head.
Distribution: Slackware (15 current), Slack15, Ubuntu studio, MX Linux, FreeBSD 13.1, WIn10
Posts: 10,342

Rep: Reputation: 2242Reputation: 2242Reputation: 2242Reputation: 2242Reputation: 2242Reputation: 2242Reputation: 2242Reputation: 2242Reputation: 2242Reputation: 2242Reputation: 2242
Quote:
Originally Posted by Turbocapitalist View Post
As Emerson writes the manual page for "visudo" covers a lot of that, but the gist is that it checks syntax. That's better than nothing. You can still lock yourself out even with correct syntax if you tell it to.

If you use "nano" be sure to fire it up with the -w option or even add nowrap to .nanorc so it is done automatically. Some distros will ask you the first time you fire up "visudo" if you want to use "nano" for the editor and set it as the default. Otherwise, you can be sure that the $EDITOR environment variable is set to "nano" and "visudo" will use it then.
yeah I read that man page and well it is just me using editing that file and I don't really do a lot of mods to it, just set my just me user to wheel all for sudo no password and that is the end of that. for what it is set up for for them that edit sudoers file a lot to make all of them adjustments to that file and with the maybe more then one editing that file at a time thing yes I can then see the benifts to using visodo other then that me perosnally i have no need of it.

thanks for your time...
 
Old 10-03-2016, 05:57 AM   #7
dushyantg
Member
 
Registered: Jun 2016
Posts: 70

Original Poster
Rep: Reputation: Disabled
I am using CentOS 7 and only want to do it for 2 services.
 
Old 10-03-2016, 06:32 AM   #8
Turbocapitalist
LQ Guru
 
Registered: Apr 2005
Distribution: Linux Mint, Devuan, OpenBSD
Posts: 7,295
Blog Entries: 3

Rep: Reputation: 3719Reputation: 3719Reputation: 3719Reputation: 3719Reputation: 3719Reputation: 3719Reputation: 3719Reputation: 3719Reputation: 3719Reputation: 3719Reputation: 3719
Quote:
Originally Posted by dushyantg View Post
I am using CentOS 7 and only want to do it for 2 services.
Ok. CentOS 7 has "sudo". Which two services? And does the example above in #2 for Apache2 help?
 
  


Reply



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
How to check which user start or stop the httpd service raja_2312 Linux - Newbie 2 08-12-2016 04:46 AM
create subfolder with same user/group permission ! shipon_97 Linux - Newbie 1 09-16-2015 07:10 AM
How to create an FTP user with permission to access only one specific directory guhan.p Linux - Server 1 08-07-2014 10:56 AM

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

All times are GMT -5. The time now is 12:05 PM.

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
Open Source Consulting | Domain Registration