Granting a sftp user access to a /var/www directory
I've created a user and made his home directory /var/www/mysite/ftpdir
I've also added a Match user entry for this user in sshd_config with a ChrootDirectory that points to /var/www/mysite
I've restarted ssh to pick this up.
When I log in with sftp - the user still goes to the user's old directory ie /home/user
What am I missing?
13 Answers
This is the process:
Add the user to the group:
sudo usermod -aG www blubas in Whats the simplest way to edit and add files to "/var/www"?or just use
sudo adduser <username> www-data- Install vsftpd
sudo apt-get install vsftpd Configure vsftpd for remote access:
sudo nano /etc/vsftpd.confand inside the file setchroot_local_user=YESand ensure this is commented out:
#chroot_list_enable=YESas per documentation.
- Restart nsftp:
sudo service vsftpd restart Configure the user's home directory to the web directory (not in
/home):sudo usermod -d /var/www/mysite/ftpaccessdir <username>Configure ssh chroot
sudo nano /etc/ssh/sshd_configadd the following to the end:
Subsystem sftp internal-sftp Match user <username> ChrootDirectory /var/www/site ForceCommand internal-sftp AllowTcpForwarding noand ensure that further up in the file that this is commented out (ie before the one you just added)
#Subsystem sftp /usr/lib/openssh/sftp-serverRestart ssh
sudo service ssh restartChange the permissions for apache:
chown root:root /var/www chown root:root /var/www/site chmod 755 /var/wwwAs in the docs here.
Ensure that your directory has www-data access
sudo chown -R www-data:www-data /var/www/site chmod 755 /var/www/site
I've a simple method and that worked for me for apache.
sudo useradd -d /var/www demo_user -g www-data
sudo passwd demo_user
sudo service ssh restartThat's it in case you still face permission issue use chmod and chown to address them according to your needs.
If you are getting connection refused error at end then make sure that "Subsystem sftp internal-sftp" is place after "UsePAM yes". If not then update and Restart ssh and it worked.
More in general
"Zoraya ter Beek, age 29, just died by assisted suicide in the Netherlands. She was physically healthy, but psychologically depressed. It's an abomination that an entire society would actively facilitate, even encourage, someone ending their own life because they had no hope. Th…"