{"id":889,"date":"2012-01-18T19:12:05","date_gmt":"2012-01-19T00:12:05","guid":{"rendered":"http:\/\/it.thelibrarie.com\/weblog\/?p=889"},"modified":"2012-01-18T19:12:05","modified_gmt":"2012-01-19T00:12:05","slug":"sudoers-ubuntu-commands","status":"publish","type":"post","link":"https:\/\/it.thelibrarie.com\/weblog\/2012\/01\/sudoers-ubuntu-commands\/","title":{"rendered":"Sudoers Ubuntu Commands"},"content":{"rendered":"<p>I needed to find an easy, and fairly secure, way to allow a user to login on a website and display their current user&#8217;s disk usage.  Generally I just navigate to the user&#8217;s home directory and run<br \/>\n<code>du -hc<\/code><br \/>\nBut in this case I needed it to work from the web.<\/p>\n<p>By default, Ubuntu runs apache as www-data.  Enter sudoers.  My editor&#8217;s file is nano.<br \/>\n<code>visudo<\/code><br \/>\nAdd the following to the bottom of the file:<br \/>\n<code>www-data  ALL=NOPASSWD:  \/usr\/bin\/du, \/usr\/bin\/ls, other\/command<\/code><br \/>\nSave and quit<\/p>\n<p>Now your www-data user can run those commands by running sudo command.  And it will not allow the user to sudo any other commands.<\/p>\n<p>My PHP page is as follows:<br \/>\n<code>echo exec(\"sudo du -hc \/mnt\/ | grep \" . $_SESSION[\"valid_user\"] . \"| awk '{print $1}'\") . \" Disk Space Used<br \/>\";<\/code><br \/>\nObviously the SESSION variable comes from a login page, but it&#8217;s a pretty good start for me.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>I needed to find an easy, and fairly secure, way to allow a user to login on a website and display their current user&#8217;s disk usage. Generally I just navigate to the user&#8217;s home directory and run du -hc But in this case I needed it to work from the web. By default, Ubuntu runs &hellip; <a href=\"https:\/\/it.thelibrarie.com\/weblog\/2012\/01\/sudoers-ubuntu-commands\/\" class=\"more-link\">Continue reading <span class=\"screen-reader-text\">Sudoers Ubuntu Commands<\/span> <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[7],"tags":[],"class_list":["post-889","post","type-post","status-publish","format-standard","hentry","category-linux"],"_links":{"self":[{"href":"https:\/\/it.thelibrarie.com\/weblog\/wp-json\/wp\/v2\/posts\/889","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/it.thelibrarie.com\/weblog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/it.thelibrarie.com\/weblog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/it.thelibrarie.com\/weblog\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/it.thelibrarie.com\/weblog\/wp-json\/wp\/v2\/comments?post=889"}],"version-history":[{"count":1,"href":"https:\/\/it.thelibrarie.com\/weblog\/wp-json\/wp\/v2\/posts\/889\/revisions"}],"predecessor-version":[{"id":890,"href":"https:\/\/it.thelibrarie.com\/weblog\/wp-json\/wp\/v2\/posts\/889\/revisions\/890"}],"wp:attachment":[{"href":"https:\/\/it.thelibrarie.com\/weblog\/wp-json\/wp\/v2\/media?parent=889"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/it.thelibrarie.com\/weblog\/wp-json\/wp\/v2\/categories?post=889"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/it.thelibrarie.com\/weblog\/wp-json\/wp\/v2\/tags?post=889"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}