{"id":1600,"date":"2019-01-06T10:25:12","date_gmt":"2019-01-06T10:25:12","guid":{"rendered":"https:\/\/scunster.co.uk\/?p=1600"},"modified":"2019-01-06T11:47:49","modified_gmt":"2019-01-06T11:47:49","slug":"allow-starting-stopping-and-restarting-a-system-service-as-a-specific-user-without-su-password","status":"publish","type":"post","link":"https:\/\/scunster.co.uk\/?p=1600","title":{"rendered":"Allow starting, stopping and restarting a system service as a specific user (without su password)"},"content":{"rendered":"<p>In this example we are going to allow the system user &#8220;minecraft&#8221; to start, stop and restart the system services mincecraft, minecraft2 and minecraftpe<\/p>\n<p>I&#8217;ve tested this in CentOS7 and Debian 9, it may be slightly different to control services in other disto&#8217;s<\/p>\n<p>Normally only root can control services unless the user is part of the su group or specific service control has been setup in a file created in the \/etc\/sudoers.d directory<\/p>\n<p>You will either need to be logged in as root or use su to issue the following commands<\/p>\n<p>Let&#8217;s start by adding the minecraft user to the sudo group<\/p>\n<pre>usermod -aG sudo minecraft<\/pre>\n<p>Now we will create the file in the sudoers directory using visudo, this will define which services the minecraft user can use without su password<\/p>\n<pre>visudo -f \/etc\/sudoers.d\/minecraft<\/pre>\n<p>Next, add the following (change the service names to meet your specific requirements)<\/p>\n<pre>minecraft ALL = NOPASSWD: \/bin\/systemctl stop minecraft.service, \/bin\/systemctl$ start minecraft.service, \/bin\/systemctl start minecraft2.service, \/bin\/systemctl stop minecraft2.service, \/bin\/systemctl start minecraftpe.service, \/bin\/systemctl stop minecraftpe.service<\/pre>\n<p>Now we need to restart the sudo service<\/p>\n<pre>service sudo restart<\/pre>\n<p>Assuming you have already created the relevant services to be controlled, log in as your user and you should have full control of your service(s) with<\/p>\n<pre>sudo systemctl start minecraft<\/pre>\n<pre>sudo systemctl stop minecraft<\/pre>\n<pre>sudo systemctl reload minecraft<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>In this example we are going to allow the system user &#8220;minecraft&#8221; to start, stop and restart the system services mincecraft, minecraft2 and minecraftpe I&#8217;ve tested this in CentOS7 and Debian 9, it may be slightly different to control services in other disto&#8217;s Normally only root can control services unless the user is part of [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[164,131],"tags":[451,401,452,447,445,454,449,448,450,446,453],"class_list":["post-1600","post","type-post","status-publish","format-standard","hentry","category-centos","category-ubuntu-linux","tag-password","tag-restart","tag-service","tag-services","tag-start","tag-stop","tag-sudo","tag-sudoer","tag-sudoers","tag-systemctl","tag-user"],"_links":{"self":[{"href":"https:\/\/scunster.co.uk\/index.php?rest_route=\/wp\/v2\/posts\/1600","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/scunster.co.uk\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/scunster.co.uk\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/scunster.co.uk\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/scunster.co.uk\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=1600"}],"version-history":[{"count":3,"href":"https:\/\/scunster.co.uk\/index.php?rest_route=\/wp\/v2\/posts\/1600\/revisions"}],"predecessor-version":[{"id":1607,"href":"https:\/\/scunster.co.uk\/index.php?rest_route=\/wp\/v2\/posts\/1600\/revisions\/1607"}],"wp:attachment":[{"href":"https:\/\/scunster.co.uk\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=1600"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/scunster.co.uk\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=1600"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/scunster.co.uk\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=1600"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}