Skip to content

Instantly share code, notes, and snippets.

@refo
Last active December 1, 2020 16:33
Show Gist options
  • Save refo/3fd3e9336fee84f5f87968d20312340a to your computer and use it in GitHub Desktop.
Save refo/3fd3e9336fee84f5f87968d20312340a to your computer and use it in GitHub Desktop.
Enable sftp for ubuntu user

sshd configuration

Assuming username is blog and target folder is /home/blog

Make sure user blog is exists and necessary permissions for the target folder is already set.

sudo nano /etc/ssh/sshd_config.d/blog.conf
Match User blog
  ForceCommand internal-sftp
  PasswordAuthentication yes
  ChrootDirectory /home/blog
  PermitTunnel no
  AllowAgentForwarding no
  AllowTcpForwarding no
  X11Forwarding no
sudo systemctl restart sshd

Now user may connect using sftp with the login credentials.

Give user access to files and directories of another group

Let's say there is a folder called wordpress in user's home directory and this directory is owned by www-data user and group.

sudo usermod -a -G www-data blog

chmod g+rwxs /home/blog/wordpress

This will add blog user to www-data group and give group access to files and directories in this folder even if they are; let's say 755 only user writable, now they are and any future files created in are group writable.

More detail from an askubuntu user: https://askubuntu.com/a/244410/1153321

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment