{"id":1296,"date":"2016-03-16T10:51:12","date_gmt":"2016-03-16T08:51:12","guid":{"rendered":"http:\/\/www.ludovicocaldara.net\/dba\/?p=1296"},"modified":"2016-03-24T11:17:50","modified_gmt":"2016-03-24T09:17:50","slug":"bash-tips-1-personal-accounts-permissions","status":"publish","type":"post","link":"https:\/\/www.ludovicocaldara.net\/dba\/bash-tips-1-personal-accounts-permissions\/","title":{"rendered":"Bash tips &#038; tricks [ep. 1]: Deal with personal accounts and file permissions"},"content":{"rendered":"<p>This is the first episode of a mini series of Bash tips for Linux (in case you are wondering, yes, they are respectively my favorite shell and my favorite OS \ud83d\ude09 ).<\/p>\n<p>Episode 1: <a href=\"https:\/\/www.ludovicocaldara.net\/dba\/bash-tips-1-personal-accounts-permissions\/\">Deal with personal accounts and file permissions<\/a><br \/>\nEpisode 2: <a href=\"https:\/\/www.ludovicocaldara.net\/dba\/bash-tips-2-smart-env-personal-accounts\/\">Have a smart environment for personal accounts<\/a><br \/>\nEpidode 3: <a href=\"https:\/\/www.ludovicocaldara.net\/dba\/bash-tips-3-colour-your-terminal\/\">Colour your terminal!<br \/>\n<\/a>Episode 4: <a href=\"https:\/\/www.ludovicocaldara.net\/dba\/bash-tips-4-use-logging-levels\/\">Use logging levels<\/a><br \/>\nEpisode 5: <a href=\"https:\/\/www.ludovicocaldara.net\/dba\/bash-tips-5-output-logfile\/\">Write the output to a logfile<br \/>\n<\/a>Episode 6: <a href=\"https:\/\/www.ludovicocaldara.net\/dba\/bash-tips-6-check-the-exit-code\/\">Check the exit code<\/a><br \/>\nEpisode 7: <a href=\"https:\/\/www.ludovicocaldara.net\/dba\/bash-tips-7-cleanup-on-exit\/\">Cleanup on EXIT with a trap<\/a><\/p>\n<p><strong>Description:<\/strong><\/p>\n<p>Nowadays it is mandatory at many companies to log in on Linux servers with a personal account (either integrated with LDAP, kerberos or whatelse) to comply with strict auditing rules.<\/p>\n<p>I need to be sure that I have an environment where my modifications do not conflict with my colleagues environment.<\/p>\n<p><strong>BAD<\/strong>:<\/p>\n<pre class=\"lang:sh decode:true\">-bash-4.1$ id\r\nuid=20928(ludo) gid=200(dba) groups=200(dba)\r\n-bash-4.1$ ls -lia\r\ntotal 8\r\n8196 drwxrwxr-x   2 oracle dba  4096 Mar 15 15:14 .\r\n   2 drwxrwxrwt. 14 root   root 4096 Mar 15 15:15 ..\r\n-bash-4.1$ vi script.sh\r\n... edit here...\r\n-bash-4.1$ ls -l\r\ntotal 4\r\n-rw-r--r-- 1 ludo  dba 8 Mar 15 15:15 script.sh\r\n-bash-4.1$\r\n<\/pre>\n<p>the script has been created by me, but my colleagues may need to modify it! So I need to change the ownership:<\/p>\n<pre class=\"lang:sh decode:true\">$ chown oracle:dba script.sh\r\nchown: changing ownership of `script.sh': Operation not permitted\r\n$<\/pre>\n<p>But I can only change the permissions:<\/p>\n<pre class=\"lang:sh decode:true\">$ chmod 775 script.sh\r\n$<\/pre>\n<p>If I really want to change the owner, I have to ask to someone that has root privileges or delete the file with my account and create it with the correct one (oracle or something else).<\/p>\n<p><strong>GOOD:<\/strong><\/p>\n<ul>\n<li>Set the setgid bit at the directory level<\/li>\n<li>Define an alias for my favorite editor that use sudoedit instead:<\/li>\n<\/ul>\n<pre class=\"lang:sh decode:true \">$ chmod 2751 .\r\n$ ls -lia\r\ntotal 4\r\n8196 drwxr-s--x 2 oracle dba  4096 Mar 15 15:26 .\r\n$ alias vi='SUDO_EDITOR=\/usr\/bin\/vim sudoedit -u oracle '\r\n$ vi script.sh\r\n[sudo] password for ludo:\r\n... edit here ...\r\n$ ls -l script.sh\r\ntotal 8\r\n-rw-r--r-- 1 oracle dba 6 Mar 15 15:24 script.sh\r\n$<\/pre>\n<p>In case I need to modify other files with MY account, I can either use the full path (\/usr\/bin\/vim) or define another alias:<\/p>\n<pre class=\"lang:sh decode:true \">alias vime=\"\/usr\/bin\/vim\"<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>This is the first episode of a mini series of Bash tips for Linux (in case you are wondering, yes, they are respectively my favorite shell and my favorite OS \ud83d\ude09 ). Episode 1: Deal with personal accounts and file &hellip; <a href=\"https:\/\/www.ludovicocaldara.net\/dba\/bash-tips-1-personal-accounts-permissions\/\">Continue reading <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[5,132],"tags":[26,271,285,266,268,270,267,269],"class_list":["post-1296","post","type-post","status-publish","format-standard","hentry","category-linux","category-triblog","tag-bash","tag-file-ownership","tag-linux","tag-permissions","tag-personal-account","tag-setgid","tag-shared-environment","tag-shell"],"aioseo_notices":[],"_links":{"self":[{"href":"https:\/\/www.ludovicocaldara.net\/dba\/wp-json\/wp\/v2\/posts\/1296","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.ludovicocaldara.net\/dba\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.ludovicocaldara.net\/dba\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.ludovicocaldara.net\/dba\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.ludovicocaldara.net\/dba\/wp-json\/wp\/v2\/comments?post=1296"}],"version-history":[{"count":14,"href":"https:\/\/www.ludovicocaldara.net\/dba\/wp-json\/wp\/v2\/posts\/1296\/revisions"}],"predecessor-version":[{"id":1355,"href":"https:\/\/www.ludovicocaldara.net\/dba\/wp-json\/wp\/v2\/posts\/1296\/revisions\/1355"}],"wp:attachment":[{"href":"https:\/\/www.ludovicocaldara.net\/dba\/wp-json\/wp\/v2\/media?parent=1296"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.ludovicocaldara.net\/dba\/wp-json\/wp\/v2\/categories?post=1296"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.ludovicocaldara.net\/dba\/wp-json\/wp\/v2\/tags?post=1296"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}