<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en-GB">
	<id>https://wiki.apoyar.eu/api.php?action=feedcontributions&amp;feedformat=atom&amp;user=78.99.38.137</id>
	<title>Apoyar Wiki - User contributions [en-gb]</title>
	<link rel="self" type="application/atom+xml" href="https://wiki.apoyar.eu/api.php?action=feedcontributions&amp;feedformat=atom&amp;user=78.99.38.137"/>
	<link rel="alternate" type="text/html" href="https://wiki.apoyar.eu/index.php?title=Special:Contributions/78.99.38.137"/>
	<updated>2026-07-21T03:47:21Z</updated>
	<subtitle>User contributions</subtitle>
	<generator>MediaWiki 1.41.0</generator>
	<entry>
		<id>https://wiki.apoyar.eu/index.php?title=SFTP_user_chrooted_to_wwwroot_subfolder_(Nginx)&amp;diff=108</id>
		<title>SFTP user chrooted to wwwroot subfolder (Nginx)</title>
		<link rel="alternate" type="text/html" href="https://wiki.apoyar.eu/index.php?title=SFTP_user_chrooted_to_wwwroot_subfolder_(Nginx)&amp;diff=108"/>
		<updated>2019-07-05T09:01:39Z</updated>

		<summary type="html">&lt;p&gt;78.99.38.137: Created page with &amp;quot;First, we need to change the location of the public keys for users. Otherwise we will never set the user&amp;#039;s home folder properly.  The common place for all users&amp;#039; authorized_ke...&amp;quot;&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;First, we need to change the location of the public keys for users. Otherwise we will never set the user&#039;s home folder properly.&lt;br /&gt;
&lt;br /&gt;
The common place for all users&#039; authorized_keys files will be in /usr/share/sshkeys:&lt;br /&gt;
mkdir /usr/share/sshkeys&lt;br /&gt;
&lt;br /&gt;
Then we change the sshd config to look here for the public keys:&lt;br /&gt;
vi /etc/ssh/sshd_config&lt;br /&gt;
Find and edit this line (create if doesn&#039;t exist):&lt;br /&gt;
AuthorizedKeysFile /usr/share/sshkeys/%u&lt;br /&gt;
Move all users&#039; authorized_keys here. There is no way around this. And this must be done in the future for each new user who will want to use key authentication:&lt;br /&gt;
mv /home/someuser/.ssh/authorized_keys /usr/share/sshkeys/someuser&lt;br /&gt;
Repeat the above for all users with SSH key-based access, also copy here a public key of our new SFTP user (lets call him sftpuser)&lt;br /&gt;
Set the permissions (or check them) and create a symlink back to the /home/someuser/.ssh (for all users):&lt;br /&gt;
chown someuser /usr/share/sshkeys/someuser&lt;br /&gt;
chmod 600 /usr/share/sshkeys/someuser&lt;br /&gt;
ln -s /usr/share/sshkeys/someuser /home/someuser/.ssh/authorized_keys&lt;br /&gt;
If you already have the SFTP home folder created, do it for the SFTP user as well, if not, ignore the following 3 lines:&lt;br /&gt;
chown someuser /usr/share/sshkeys/sftpuser&lt;br /&gt;
chmod 600 /usr/share/sshkeys/sftpuser&lt;br /&gt;
ln -s /usr/share/sshkeys/sftpuser /var/www/siterootfolder/sftp(sub)folder/.ssh/authorized_keys&lt;br /&gt;
Once happy, restart the sshd to apply the changes:&lt;br /&gt;
systemctl restart sshd&lt;br /&gt;
&lt;br /&gt;
Then, add the user. He will need to be in the nginx group (usually www-data) and his home folder will be set to the desired site subfolder:&lt;br /&gt;
useradd -m -d /var/www/siterootfolder/sftp(sub)folder/ -G www-data -s /usr/sbin/nologin sftpuser&lt;br /&gt;
The /usr/bin/nologin shell is there because we don&#039;t want the user to be able to log in via SSH&lt;br /&gt;
The www-data user also needs to be added to the sftpuser&#039;s group:&lt;br /&gt;
Usermod -a -G sftpuser www-data&lt;br /&gt;
&lt;br /&gt;
Edit the /etc/ssh/sshd_config file again to add chroot:&lt;br /&gt;
vi /etc/ssh/sshd_config&lt;br /&gt;
Add (or uncomment) the sftp paragraph:&lt;br /&gt;
Match User sftpuser&lt;br /&gt;
    ChrootDirectory /var/www/siterootfolder/sftp(sub)folder/&lt;br /&gt;
    X11Forwarding no&lt;br /&gt;
    AllowTcpForwarding no&lt;br /&gt;
    ForceCommand internal-sftp&lt;br /&gt;
This way the user will only have access to his &#039;home&#039; folder, seeing it as a root folder.&lt;br /&gt;
&lt;br /&gt;
Unfortunately the sshd&#039;s internal sftp engine is very restrictive about folder permissions here. The chrooted folder, as well as its each parent (up to /) must be owned by root:root with permissions 755. To achieve this:&lt;br /&gt;
First, make sure the permissions on your site folder, subfolders and files are set correctly (particularly Magento can have problems here). Then start changing the permissions:&lt;br /&gt;
cd /&lt;br /&gt;
chown root:root var/&lt;br /&gt;
chmod 755 var/&lt;br /&gt;
cd var/&lt;br /&gt;
chown root:root www/&lt;br /&gt;
chmod 755 www/&lt;br /&gt;
cd www/&lt;br /&gt;
chown root:root siterootfolder/&lt;br /&gt;
chmod 755 siterootfolder/&lt;br /&gt;
cd siterootfolder/&lt;br /&gt;
ls -l&lt;br /&gt;
The above command is to determine the current permissions of the sftp(sub)folder. Record the owner(u) and the others&#039;(o) permissions. Why? Remember, it&#039;s not just the sftpuser in the www-data group but vice versa. This way we will have his home folder but make sure the www-data account (which Nginx is running under) will have still the same permissions.&lt;br /&gt;
chown -R sftpuser:sftpuser sftp(sub)folder/&lt;br /&gt;
In the next command make sure the owner(u) and the group permissions(g) are the same, the (o) permissions can stay as they were:&lt;br /&gt;
chmod -R xxx sftp(sub)folder/&lt;br /&gt;
And change the owner and permissions to comply with the sshd chroot conditions:&lt;br /&gt;
chown root:root sftp(sub)folder/&lt;br /&gt;
chmod 755 sftp(sub)folder/&lt;br /&gt;
Note the missing -R parameter when we are changing the parent folders&#039; owner and permissions. We don&#039;t want to mess up the permissions on the content of these folders, just the folders themselves.&lt;br /&gt;
&lt;br /&gt;
Now create the .ssh folder and link the already created public key there (if you didn&#039;t do it yet):&lt;br /&gt;
cd sftp(sub)folder/&lt;br /&gt;
mkdir .ssh&lt;br /&gt;
chown -R sftpuser:sftpuser .ssh/&lt;br /&gt;
chmod -R 700 .ssh/&lt;br /&gt;
ln -s /usr/share/sshkeys/sftpuser /var/www/siterootfolder/sftp(sub)folder/.ssh/authorized_keys&lt;br /&gt;
&lt;br /&gt;
Once you&#039;ve double-checked that all permissions are as they should be, apply the sshd_config changes:&lt;br /&gt;
systemctl restart sshd&lt;/div&gt;</summary>
		<author><name>78.99.38.137</name></author>
	</entry>
	<entry>
		<id>https://wiki.apoyar.eu/index.php?title=Complete_step-by-step_guides&amp;diff=107</id>
		<title>Complete step-by-step guides</title>
		<link rel="alternate" type="text/html" href="https://wiki.apoyar.eu/index.php?title=Complete_step-by-step_guides&amp;diff=107"/>
		<updated>2019-07-05T09:00:49Z</updated>

		<summary type="html">&lt;p&gt;78.99.38.137: /* Please choose from the following */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&amp;lt;strong&amp;gt;Step-by-step guides.&amp;lt;/strong&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Please choose from the following ==&lt;br /&gt;
* [[Add new joinee]]&lt;br /&gt;
* [[Add new server]]&lt;br /&gt;
&amp;lt;nowiki&amp;gt;======================================&amp;lt;/nowiki&amp;gt;&lt;br /&gt;
* [[Add new user to GitLab]]&lt;br /&gt;
* [[Add new server to GitLab AutoDeploy]]&lt;br /&gt;
* [[Convert the SVN repository to GitLab]]&lt;br /&gt;
* [[Installing ruby on rails with Nginx passenger]]&lt;br /&gt;
* [[Install Oracle client on Ubuntu]]&lt;br /&gt;
* [[Remove NewRelic agent]]&lt;br /&gt;
* [[Mysql Setup]]&lt;br /&gt;
* [[SFTP user chrooted to wwwroot subfolder (Nginx)]]&lt;/div&gt;</summary>
		<author><name>78.99.38.137</name></author>
	</entry>
</feed>