debian

如何使用Debian SFTP进行远程登录

小樊
47
2025-10-15 19:18:30
栏目: 智能运维

Prerequisites
Ensure your Debian system has an active internet connection and basic utilities installed. You’ll need root or sudo privileges to perform administrative tasks.

1. Install OpenSSH Server
Debian includes OpenSSH Server by default, but if it’s not installed, run:

sudo apt update && sudo apt install openssh-server -y

This installs the SSH server, which also provides SFTP functionality. The service starts automatically after installation.

2. Configure SSH for SFTP
Edit the SSH configuration file to enable SFTP and customize access rules:

sudo nano /etc/ssh/sshd_config

3. Restart SSH Service
Apply configuration changes by restarting the SSH service:

sudo systemctl restart ssh

To ensure the service starts on boot, enable it:

sudo systemctl enable ssh

4. Create SFTP Users

5. Set Home Directory Permissions
For SFTP to work correctly (especially with ChrootDirectory), the user’s home directory must be owned by root and have 755 permissions:

sudo chown root:root /home/your_username
sudo chmod 755 /home/your_username

If the user needs to upload files, create a subdirectory (e.g., uploads) and grant ownership to the user:

sudo mkdir /home/your_username/uploads
sudo chown your_username:your_username /home/your_username/uploads

6. Test SFTP Connection
From a remote machine (or locally), connect to the Debian server using SFTP:

sftp your_username@your_server_ip

Optional: Configure Key-Based Authentication (More Secure)
To avoid entering passwords, set up SSH key authentication:

Troubleshooting Tips

0
看了该问题的人还看了