SFTP journey
To set up an SFTP server for your existing user karl, allowing uploads to /var/www and its subdirectories while still providing SSH access without restricting him to SFTP only, follow these steps:
Prerequisites
- Ensure you have root or sudo access to the server.
- OpenSSH server should be installed.
Steps
Open SSH Configuration File:
Add/Modify SFTP Configuration: Find the section related to
Subsystem sftp. If it exists, it may look like this:If it doesn't exist, you can add it. After that, add a new section for the
karluser. Place this below theSubsystem sftpline:Set Permissions: The
ChrootDirectorymust be owned by root and not writable by anyone else. Adjust permissions as follows:For any subdirectories where
karlshould upload files, you can set ownership tokarl:Restart SSH Service: After making changes, restart the SSH service to apply the configuration:
Testing:
- Log in as
karlusing SFTP: - Try uploading a file to the
uploadsdirectory: - Ensure you can still log in via SSH:
- Log in as
Note
- The
ChrootDirectoryshould be a directory thatkarlhas permissions to write to. Ifkarlneeds to upload files to multiple directories under/var/www, you might need to repeat the ownership and permissions steps for each directory where uploads are needed. - If you have any existing files in
/var/wwwthat need to be accessible tokarl, you may want to adjust their permissions accordingly.
Troubleshooting
- If you encounter issues with SFTP access, check the SSH logs for error messages:
- Ensure that there are no syntax errors in the SSH configuration by running:
This setup allows karl to use SFTP for file uploads while still having SSH access to the server for other tasks.
Comments
Post a Comment