How can I connect to a /var/www via sftp?

Asked 2 days ago
Viewed 14 times

I want to connect to /var/www via sftp, I made the chroot directory, but /www belongs to another user and group (nginx:nginx), so it can´t connect to it, how can I do it without changing the user neither the group?

For example if I configure chroot only like /var, it works because /var belongs to root:root note: I also changed the main directory of my users (usermod -d /var/www sftp_user)


asked 2 days ago

Correct Answer

I am assuming your sftp login user is 'sftp_user'. generally you dont want to make your home to a directory where you don't want to add misc config files.

Option 1

if the group "nginx" has read/execute and write if you want that, you can add user 'sftp_user' to group 'nginx'

to check for permissions on '/var/www', execute

  • ls -l /var
  • output should contain something like
  • drwxr-xr-x 12 nginx nginx 4096 Sep 28 2021 www/
  • In this example, group 'nginx' has read/execute permission To add user 'sftp_user' to group 'nginx'
  • sudo usermod -a -G nginx sftp_user
  • this will give read/execute permission to /var/www To add write access to group 'nginx'
  • sudo chmod g+w /var/www
  • might want to check if nginx will have any problems with group write permission will be a security problem

Option 2

I use apache but it probably is the same with nginx, What i did was changed the user of '/var/www/' to my username, instead of modifying group permissions.

  • to change the all files and directorys to have user 'myuser'
  • `sudo chown myuser:www-data -R /var/www/ For you it would be
  • sudo chown sftp_user:nginx -R /var/www
  • but again you many want to check if there is any issues with thing on nginx

good luck

answered 2 days ago