{"id":2223,"date":"2018-12-18T23:10:07","date_gmt":"2018-12-18T23:10:07","guid":{"rendered":"http:\/\/www.incredigeek.com\/home\/?p=2223"},"modified":"2018-12-18T23:12:49","modified_gmt":"2018-12-18T23:12:49","slug":"bash-script-to-add-new-sftp-user-and-setup-permissions","status":"publish","type":"post","link":"https:\/\/www.incredigeek.com\/home\/bash-script-to-add-new-sftp-user-and-setup-permissions\/","title":{"rendered":"BASH Script to add new SFTP user and setup permissions"},"content":{"rendered":"\n<p>This script adds a new SFTP user with only sftp access.&nbsp; Refer to <a href=\"https:\/\/www.incredigeek.com\/home\/setup-secure-ftp-server-on-centos\/\">this <\/a>post on setting up a SFTP server.<\/p>\n\n\n\n<p>Download script<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">wget www.incredigeek.com\/home\/downloads\/scripts\/sftpUserAdd.sh<br><\/pre>\n\n\n\n<p>Make executable<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">chmod +x sftpUserAdd.sh<br><\/pre>\n\n\n\n<p>Run with the new user you want to create.<br><\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">.\/sftpUserAdd.sh sftpUsername<\/pre>\n\n\n\n<p>You may need to edit the script and modify the location parameters.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">#!\/bin\/bash<br># Automatically setup and add SFTP user<br># Script creates new user and setups permissions<br>newUser=$1<br>sftpDir=\"\/sftp\/\"<br>if grep -q ${newUser} \/etc\/passwd ;then<br>        echo ${newUser} Already exsists.  Aborting!<br>        exit 1<br>else<br>        mkdir -p ${sftpDir}\/${newUser}\/files<br>        useradd -g sftpusers -d ${sftpDir}\/${newUser}\/files -s \/sbin\/nologin ${newUser}<br>        passwd ${newUser}<br>        chown ${newUser}:sftpusers \/sftp\/CareMark\/files<br>fi<br><\/pre>\n","protected":false},"excerpt":{"rendered":"<p>This script adds a new SFTP user with only sftp access.&nbsp; Refer to this post on setting up a SFTP server. Download script wget www.incredigeek.com\/home\/downloads\/scripts\/sftpUserAdd.sh Make executable chmod +x sftpUserAdd.sh Run with the new user you want to create. .\/sftpUserAdd.sh &hellip; <a href=\"https:\/\/www.incredigeek.com\/home\/bash-script-to-add-new-sftp-user-and-setup-permissions\/\">Continue reading <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[3,266],"tags":[211,342,7,173,405,243,550,549],"class_list":["post-2223","post","type-post","status-publish","format-standard","hentry","category-linux","category-scripts","tag-bash","tag-ftp","tag-linux-2","tag-script","tag-scripting","tag-scripts","tag-user","tag-users"],"_links":{"self":[{"href":"https:\/\/www.incredigeek.com\/home\/wp-json\/wp\/v2\/posts\/2223","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.incredigeek.com\/home\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.incredigeek.com\/home\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.incredigeek.com\/home\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.incredigeek.com\/home\/wp-json\/wp\/v2\/comments?post=2223"}],"version-history":[{"count":5,"href":"https:\/\/www.incredigeek.com\/home\/wp-json\/wp\/v2\/posts\/2223\/revisions"}],"predecessor-version":[{"id":2230,"href":"https:\/\/www.incredigeek.com\/home\/wp-json\/wp\/v2\/posts\/2223\/revisions\/2230"}],"wp:attachment":[{"href":"https:\/\/www.incredigeek.com\/home\/wp-json\/wp\/v2\/media?parent=2223"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.incredigeek.com\/home\/wp-json\/wp\/v2\/categories?post=2223"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.incredigeek.com\/home\/wp-json\/wp\/v2\/tags?post=2223"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}