{"id":1561,"date":"2024-02-21T14:23:41","date_gmt":"2024-02-21T12:23:41","guid":{"rendered":"https:\/\/www.mcgill.org.za\/stuff\/?p=1561"},"modified":"2024-02-21T14:25:39","modified_gmt":"2024-02-21T12:25:39","slug":"code-snippet-create-a-scp-only-user-for-ssh","status":"publish","type":"post","link":"https:\/\/www.mcgill.org.za\/stuff\/archives\/1561","title":{"rendered":"Code snippet: This service allows sftp connections only: Create a scp-only user for ssh"},"content":{"rendered":"\n<p>This user <code>bob<\/code> can only run <code>scp<\/code>, and not get a shell by ssh.  Every other ssh-y thing he tries should get the error &#8220;This service allows sftp connections only.&#8221;<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>bob=bob                       <em># or bob=marysue<\/em>\necho >> \/etc\/ssh\/sshd_config &lt;&lt;EOF\nMatch Group sftponly\n  ChrootDirectory %h\n  ForceCommand internal-sftp -u 0002 -d \/incoming\nEOF\n\n sudo -u $bob sh -c 'mkdir ~\/incoming'  <em># here's a place for your stuff, bob<\/em>\n groupadd sftponly                      <em># group for scp and sftp only<\/em>\n usermod -a -G sftponly $bob            <em># bob: you're in it<\/em>\n chown root \/home\/$bob                  <em># sorry bob, we're going to chroot here, so you can't have it<\/em>\n<\/code><\/pre>\n\n\n\n<p>This is reasonably secure&#x2122;, but it doesn&#8217;t stop him from logging in at the console &#8230; or with <code>telnet<\/code>, or with <code>su<\/code> if he gets some other code running.  If you don&#8217;t have <code>telnet<\/code> enabled, you can enable it now for this particular security hole.  Actually, the shell should be changed to something listed in <code>\/etc\/shells<\/code> that is not a shell, but that is an exercise to the reader.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>This user bob can only run scp, and not get a shell by ssh. Every other ssh-y thing he tries should get the error &#8220;This service allows sftp connections only.&#8221; This is reasonably secure&#x2122;, but it doesn&#8217;t stop him from &hellip; <a href=\"https:\/\/www.mcgill.org.za\/stuff\/archives\/1561\">Continue reading <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":null,"sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[2],"tags":[308,307,16,190],"class_list":["post-1561","post","type-post","status-publish","format-standard","hentry","category-stuff","tag-restricted-user","tag-scp","tag-security","tag-stuff"],"_links":{"self":[{"href":"https:\/\/www.mcgill.org.za\/stuff\/wp-json\/wp\/v2\/posts\/1561","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.mcgill.org.za\/stuff\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.mcgill.org.za\/stuff\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.mcgill.org.za\/stuff\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.mcgill.org.za\/stuff\/wp-json\/wp\/v2\/comments?post=1561"}],"version-history":[{"count":3,"href":"https:\/\/www.mcgill.org.za\/stuff\/wp-json\/wp\/v2\/posts\/1561\/revisions"}],"predecessor-version":[{"id":1564,"href":"https:\/\/www.mcgill.org.za\/stuff\/wp-json\/wp\/v2\/posts\/1561\/revisions\/1564"}],"wp:attachment":[{"href":"https:\/\/www.mcgill.org.za\/stuff\/wp-json\/wp\/v2\/media?parent=1561"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.mcgill.org.za\/stuff\/wp-json\/wp\/v2\/categories?post=1561"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.mcgill.org.za\/stuff\/wp-json\/wp\/v2\/tags?post=1561"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}