Setting up a secure file transfer system with SFTP (SSH File Transfer Protocol) is one of the most reliable ways to manage files on a remote server. In this article, we’ll walk through setting up an SFTP server on Ubuntu, configuring a dedicated user, generating keys with PuTTYgen (Windows), and connecting via WinSCP. We’ll also cover some common pitfalls you may encounter along the way.
Step 1: Create a Dedicated SFTP User
It’s a bad idea to upload/manage web files as root. Instead, create a user specifically for SFTP access.
sudo adduser itindianet
When prompted, set a strong password (or leave it empty if you plan to use keys only).
Then, set the home directory and create a web root:
sudo usermod -d /home/itindianet -m itindianet
sudomkdir-p /home/itindianet/public_html
sudochown-R itindianet:itindianet /home/itindianet/public_html
Now your user has a safe home directory with public_html
for web files.
Step 2: Adjust Apache DocumentRoot
Update Apache’s config (/etc/apache2/sites-available/yourdomain.conf
) so it points to the new user’s web root:
DocumentRoot /home/itindianet/public_html
<Directory /home/itindianet/public_html>
Options -Indexes +FollowSymLinks
AllowOverride All
Require all granted
</Directory>
Reload Apache:
sudo apache2ctl configtest
sudo systemctl reload apache2
Step 3: Generate SSH Keys with PuTTYgen (Windows)
If you’re using Windows, the easiest way to generate keys is with PuTTYgen.
- Open PuTTYgen.
- Select RSA as the key type (not SSH-1).
- Set key length: 2048 or 3072 bits.
- Click Generate and move your mouse until it’s done.
- (Optional) Add a passphrase.
- Save the private key (
.ppk
) — this will be used in WinSCP. - Important: Copy the text from the box at the top labeled:Public key for pasting into OpenSSH authorized_keys file⚠️ Do not use the “Save public key” button — that saves in SSH2 format, which Ubuntu won’t accept.
Step 4: Install the Public Key on the Server
On Ubuntu, create the .ssh
folder for the user:
sudomkdir-p /home/itindianet/.ssh
sudo nano /home/itindianet/.ssh/authorized_keys
Paste the one-line OpenSSH key (the ssh-rsa AAAAB3...
line from PuTTYgen).
Fix permissions:
sudo chown-R itindianet:itindianet /home/itindianet/.ssh
sudo chmod 700 /home/itindianet/.ssh
sudo chmod600 /home/itindianet/.ssh/authorized_keys
Restart SSH:
sudo systemctl restartssh
Step 5: Connect with WinSCP
- Open WinSCP.
- Protocol: SFTP
- Host:
yourdomain.com
- Username:
itindianet
- Private key file: select your
.ppk
- Leave password blank (unless you added a passphrase).
You should now be able to connect securely.
Stats:
- 80%+ of data breaches involve weak or stolen credentials (Verizon DBIR 2023).
- SSH/SFTP with key authentication is up to 10x more secure than password-based authentication, due to resistance against brute-force attacks.
- RSA 2048-bit keys are considered secure until at least 2030; most enterprises now prefer 3072 or Ed25519 for longer-term safety.
- Using public key authentication can reduce password-based login attempts by bots by 95%, since the server doesn’t even offer password login once disabled.
- WinSCP is one of the most used SFTP clients worldwide, with over 180 million downloads as of 2024.
Common Pitfalls (Lessons Learned)
- Wrong key format: If you paste the SSH2-style key (with
---- BEGIN SSH2 PUBLIC KEY ----
) intoauthorized_keys
, Ubuntu will reject it. Always use the OpenSSH one-line format from the PuTTYgen top box. - Permissions too open: SSH refuses to use keys if
.ssh
orauthorized_keys
permissions are loose. Stick to700
for.ssh
and600
forauthorized_keys
. - Mixing web root and keys: Never place SSH keys in
/var/www
. Keys belong in the user’s home (/home/username/.ssh/
). Keep web files in/home/username/public_html/
. - Testing locally first: Always try
sftp username@localhost
from the server itself before testing from WinSCP.