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

  1. Open SSH Configuration File:

    sudo nano /etc/ssh/sshd_config
  2. Add/Modify SFTP Configuration: Find the section related to Subsystem sftp. If it exists, it may look like this:

    Subsystem sftp /usr/lib/openssh/sftp-server

    If it doesn't exist, you can add it. After that, add a new section for the karl user. Place this below the Subsystem sftp line:

    Match User karl
    ChrootDirectory /var/www ForceCommand internal-sftp AllowTcpForwarding no X11Forwarding no
  3. Set Permissions: The ChrootDirectory must be owned by root and not writable by anyone else. Adjust permissions as follows:

    sudo chown root:root /var/www
    sudo chmod 755 /var/www

    For any subdirectories where karl should upload files, you can set ownership to karl:

    sudo mkdir /var/www/uploads
    sudo chown karl:karl /var/www/uploads
  4. Restart SSH Service: After making changes, restart the SSH service to apply the configuration:

    sudo systemctl restart sshd
  5. Testing:

    • Log in as karl using SFTP:
      sftp karl@caputxeta
    • Try uploading a file to the uploads directory:
      put local_file.txt uploads/
    • Ensure you can still log in via SSH:
      ssh karl@caputxeta

Note

  • The ChrootDirectory should be a directory that karl has permissions to write to. If karl 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 to karl, you may want to adjust their permissions accordingly.

Troubleshooting

  • If you encounter issues with SFTP access, check the SSH logs for error messages:
    sudo tail -f /var/log/auth.log
  • Ensure that there are no syntax errors in the SSH configuration by running:
    sudo sshd -t

This setup allows karl to use SFTP for file uploads while still having SSH access to the server for other tasks.

Comments

Popular posts from this blog

Tutorials on Unity Probuilder and Progrids

difference between field and property in c#