Normally we have a common security setup for the servers which we described on our guide on basic server setup and ensuring security. Paid web hosting control panels like cPanel usually have either no shell but FTP or SFTP access or limited shell access. Often we need to host account on vps or cloud server where it is desired to have a setup sftp without shell access for WordPress Like cPanel. We are using Ubuntu 16.04 as server operating system and WordPress files as FTP content.
Of course we have softwares like vsftd and with Fail2Ban the security can be made more. But username of FTP and shell if set as different then it is actually safer for one server one IP one user/website too.
Setup SFTP Without Shell Access For WordPress, Cloud Server
We are taking that WordPress is not installed yet. First, from shell we need to create a user, the name should be difficult to guess and thecustomizewindows
is example here :
---
1 | sudo adduser thecustomizewindows |
You’ll prompted for password. Other details is optional, you can hit ENTER to leave those fields blank. Run these commands to check whether the outputs are meaningfully correct :
1 2 | id thecustomizewindows ls -lad /home/thecustomizewindows/ |
The target can be achieved in many ways but this is easy :
1 2 3 4 5 6 7 8 | mkdir /home/thecustomizewindows/sites/public/ mkdir /home/thecustomizewindows/sites/public/html/ mkdir /home/thecustomizewindows/sites/logs sudo chown root:root /home/thecustomizewindows/sites sudo chmod 755 /home/thecustomizewindows/sites sudo chmod 755 /home/thecustomizewindows/sites/logs sudo chown thecustomizewindows /home/thecustomizewindows/sites/public/ sudo chown thecustomizewindows /home/thecustomizewindows/sites/logs |
So, /home/thecustomizewindows/sites/public/
is the location where we will have the WordPress site as well as the user can have SFTP access.
We need some modification of /etc/ssh/sshd_config
file :
1 | nano /etc/ssh/sshd_config |
Make sure the configuration looks like :
1 2 3 4 5 6 7 8 9 10 | ... Match User sammyfiles ForceCommand internal-sftp PasswordAuthentication yes ChrootDirectory /home/thecustomizewindows/sites PermitTunnel no AllowAgentForwarding no AllowTcpForwarding no X11Forwarding no ... |
save the file. Run these commands :
1 2 3 | /etc/init.d/sshd restart sudo service ssh restart exit |
Test to SSH :
1 | ssh thecustomizewindows@your.IP.address |
You should see the error :
1 2 | This service allows sftp connections only. Connection to localhost closed. |
Steps For Setup WordPress On Our SFTP Without Shell Access
Of course we need change in virtual host configuration (we are taking that Apache2 is running, normally we install Apache2 in this way) :
1 2 3 4 5 6 7 8 9 | ... <VirtualHost *:80> ServerName thecustomizewindows.example.com ServerAdmin webmaster@example.com DocumentRoot /home/thecustomizewindows/sites/public/ ErrorLog ${APACHE_LOG_DIR}/error.log CustomLog /home/thecustomizewindows/sites/logs/access.log combined ... |
Run :
1 2 | apachectl -t sudo systemctl restart apache2.service |
Make sure that the file really can be created by Apache :
1 | /home/thecustomizewindows/sites/logs/access.log |
Now you can normally install WordPress as SFTP user in the way you want. If you do FTP via client like Filezilla, you can only edit files from :
1 | /home/thecustomizewindows/sites/public/ |
Of course access log will be available :
1 | /home/thecustomizewindows/sites/logs/access.log |