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
karl
user. Place this below theSubsystem sftp
line:Set Permissions: The
ChrootDirectory
must be owned by root and not writable by anyone else. Adjust permissions as follows:For any subdirectories where
karl
should 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
karl
using SFTP: - Try uploading a file to the
uploads
directory: - Ensure you can still log in via SSH:
- Log in as
Note
- The
ChrootDirectory
should be a directory thatkarl
has permissions to write to. Ifkarl
needs 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/www
that 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