Skip to content

Instantly share code, notes, and snippets.

@manimike00
Last active April 25, 2020 06:11
Show Gist options
  • Save manimike00/8e568f32203c2f1c36067ccebf0c81c3 to your computer and use it in GitHub Desktop.
Save manimike00/8e568f32203c2f1c36067ccebf0c81c3 to your computer and use it in GitHub Desktop.
SFTP setup
To Create a SFTP server for user to login and access particular folder
Steps 1: Create an additional folder and assign root access alone
# mkdir -p /data
# chmod 701 /data
Step 2: Create a group for the SFTP user's
# groupadd group-name
Step 3: Create User and assign Password
# useradd -g group-name -d /upload -s /sbin/nologin user-name
# passwd user-name
Step 4: Assign Ownership to directories accordingly
# mkdir -p /data/user-name/upload
# chown -R root:group-name /data/user-name
# chown -R user-name:group-name /data/user-name/upload
Step 5: Edit /etc/ssh/sshd_config and add those line at the bottom.
(Its Enough editing once and every time adding user it applies to every user)
# nano /etc/ssh/sshd_config
Match Group group-name
ChrootDirectory /data/%u
ForceCommand internal-sftp
Step 6: Restart the SSH service
# systemctl restart ssh
Step 7: Testing
# sftp -i "key-pair" user-name@IPaddress
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment