{"id":1812,"date":"2022-01-26T13:10:00","date_gmt":"2022-01-26T13:10:00","guid":{"rendered":"https:\/\/www.qworqs.com\/?p=1812"},"modified":"2022-10-09T23:41:35","modified_gmt":"2022-10-09T23:41:35","slug":"giving-sftp-access-to-a-user-for-a-certain-directory","status":"publish","type":"post","link":"https:\/\/www.voodoo.business\/blog\/2022\/01\/26\/giving-sftp-access-to-a-user-for-a-certain-directory\/","title":{"rendered":"Giving SFTP access to a user for a certain directory !"},"content":{"rendered":"\n<p>In this mini tutorial, I will be adding the user kareem to the system, and allow kareem to sftp into a web directory where he can post his web design work, as usual, the steps first, then whatever explanations !<\/p>\n\n\n\n<p>There are two ways to do this, one to add one user, the other to add a group of users, you can either pick one, or do both !<\/p>\n\n\n\n<p>The part in common between both solutions<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">apt-get install openssh-server\nadduser kareem\nThen enter a new password twice for kareem\n<\/pre>\n\n\n\n<p>The interesting thing about this sftp user business is that the directory we will specify as the root for the user kareem has to be owned by root ! so go ahead and create the directory \/var\/www\/html\/usr\/kareem, then execute the following commands<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">chown root:root \/var\/www\/html\/usr\nchmod 755 \/var\/www\/html\/usr\n\nchown kareem:kareem \/var\/www\/html\/usr\/kareem<\/pre>\n\n\n\n<p>Now, the user kareem owns a directory within his root directory that he can write to, and can not write outside that directory since he does not have the OS permissions, Now, let us add kareem to the list of people who have sftp access but not ssh access.<\/p>\n\n\n\n<p>Edit <strong><em>\/etc\/ssh\/sshd_config<\/em><\/strong> and append the following to the document<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">Match User kareem\nForceCommand internal-sftp\nPasswordAuthentication yes\nChrootDirectory \/var\/www\/html\/usr\nPermitTunnel no\nAllowAgentForwarding no\nAllowTcpForwarding no\nX11Forwarding no\n<\/pre>\n\n\n\n<p>Now, restart the service by executing the following command<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">systemctl restart ssh<\/pre>\n\n\n\n<p>You are done, try connecting with something like winSCP<\/p>\n\n\n\n<p>Besides winSCP, you can also simply mount the linux filesystem where you have permissions on your windows machine, here are the complete instructions on how to do that <a href=\"\/2022\/10\/09\/mounting-a-remote-linux-file-system-as-a-windows-drive\/\">https:\/\/www.qworqs.com\/2022\/10\/09\/mounting-a-remote-linux-file-system-as-a-windows-drive\/<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>In this mini tutorial, I will be adding the user kareem to the system, and allow kareem to sftp into a web directory where he can post his web design work, as usual, the steps first, then whatever explanations ! There are two ways to do this, one to add one user, the other to [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[155,4,154],"tags":[],"class_list":["post-1812","post","type-post","status-publish","format-standard","hentry","category-ftp","category-linux","category-sftp"],"_links":{"self":[{"href":"https:\/\/www.voodoo.business\/blog\/wp-json\/wp\/v2\/posts\/1812","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.voodoo.business\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.voodoo.business\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.voodoo.business\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.voodoo.business\/blog\/wp-json\/wp\/v2\/comments?post=1812"}],"version-history":[{"count":12,"href":"https:\/\/www.voodoo.business\/blog\/wp-json\/wp\/v2\/posts\/1812\/revisions"}],"predecessor-version":[{"id":1923,"href":"https:\/\/www.voodoo.business\/blog\/wp-json\/wp\/v2\/posts\/1812\/revisions\/1923"}],"wp:attachment":[{"href":"https:\/\/www.voodoo.business\/blog\/wp-json\/wp\/v2\/media?parent=1812"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.voodoo.business\/blog\/wp-json\/wp\/v2\/categories?post=1812"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.voodoo.business\/blog\/wp-json\/wp\/v2\/tags?post=1812"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}