In 2025–2026, securely transferring files to and from remote servers remains essential for developers, sysadmins, and DevOps teams. Legacy FTP is insecure and widely deprecated due to plain-text credentials and data. SFTP (Secure File Transfer Protocol) — built into SSH — provides encrypted, reliable file transfers and is the modern standard replacement.

This step-by-step how to use SFTP guide teaches you how to connect, navigate, upload/download files, manage permissions, automate transfers, and troubleshoot common issues on Linux/macOS/Windows clients. Whether you’re deploying code, backing up data, or managing remote servers, mastering SFTP ensures secure, efficient file operations.

Key Takeaways – How to Use SFTP Securely

  1. SFTP encrypts all traffic and authentication (unlike FTP); uses the same SSH credentials/keys.
  2. Connect with one command: sftp user@host (same port 22 as SSH).
  3. Interactive shell commands mimic shell: ls, cd, pwd, plus local versions (lls, lcd, lpwd).
  4. Transfer files: get (download), put (upload); supports recursive -r and preserve permissions -p/-P.
  5. Run local commands inside SFTP with ! prefix or drop to shell with !.
  6. Manage remote files: chmod, chown, chgrp, mkdir, rm, rmdir.
  7. SFTP is ideal for restricted users (chroot possible) and integrates with CI/CD pipelines.
  8. Security best practice: Use SSH keys, disable password auth, restrict SFTP-only access when needed.

Prerequisites

  1. SSH access to a remote server (Linux/macOS/Windows client).
  2. SSH key pair recommended (see: How to Set Up SSH Keys).
  3. Remote server running OpenSSH server (almost all Linux distros).

How to Connect to SFTP (Step-by-Step)

If you can SSH, you can SFTP—no extra setup required.

Basic connection:

				
					sftp username@your_server_ip_or_domain
				
			

Custom SSH port (e.g., 2222):

				
					sftp -oPort=2222 username@your_server_ip_or_domain
				
			

You’ll see the SFTP prompt:

				
					sftp>
				
			

Exit anytime:

				
					exit
# or
bye
				
			

Getting Help in SFTP

Type either:

				
					help
# or
?
				
			

Lists all commands (e.g., get, put, ls, chmod, etc.).

Navigating in SFTP (Remote & Local)

Remote commands (same as shell, but limited flags):

				
					pwd               # current remote directory
ls                # list remote files
ls -la            # detailed listing
cd /path/to/dir   # change remote directory
				
			

Local equivalents (prefix l):

				
					lpwd              # current local directory
lls               # list local files
lls -la
lcd ~/Desktop     # change local directory
				
			

Transferring Files with SFTP (Upload & Download)

Download remote → local:

				
					get remote-file.txt                # same name
get remote-file.txt local-name.txt # rename
get -r remote-folder               # recursive directory
get -Pr remote-folder              # preserve permissions/timestamps
				
			

Upload local → remote:

				
					put local-file.txt                 # same name
put local-file.txt remote-name.txt # rename
put -r local-folder                # recursive
put -Pr local-folder               # preserve permissions
				
			

Check remote disk space before big transfers:

				
					df -h
				
			

Running Local Commands Inside SFTP

Prefix with !:

				
					!ls -la           # local ls
!df -h            # local disk usage
!nano local.txt   # edit local file
				
			

Or drop to full local shell:

				
					!
# now you're in your local terminal
exit              # return to sftp>
				
			

File Management on Remote Server via SFTP

Change permissions:

				
					chmod 755 public-file.sh
chmod 644 private-config.conf
				
			

Change ownership (uses numeric UID/GID):

				
					chown 1000 file.txt          # user ID 1000
chgrp 1000 file.txt          # group ID 1000
				
			

Create/remove:

				
					mkdir new-folder
rmdir empty-folder
rm file-to-delete
rm -r folder-to-delete       # recursive remove (careful!)
				
			

How to Set Up a Basic SFTP Server (Quick Reference)

Ubuntu/Debian:

				
					sudo apt update && sudo apt install openssh-server
# Edit /etc/ssh/sshd_config → ensure: Subsystem sftp /usr/lib/openssh/sftp-server
sudo systemctl restart ssh
				
			

CentOS/RHEL/Rocky/AlmaLinux/Fedora:

				
					sudo dnf install openssh-server
# Edit /etc/ssh/sshd_config → ensure Subsystem line
sudo systemctl enable --now sshd
				
			

For SFTP-only user (no shell): Use Match User block in sshd_config with ChrootDirectory and ForceCommand internal-sftp.

Integrating SFTP into CI/CD Pipelines (2025–2026)

Use SSH keys (no passwords):

  1. Generate deploy key on CI server.
  2. Add public key to remote server’s ~/.ssh/authorized_keys.
  3. In GitHub Actions / GitLab CI / Jenkins:
				
					- name: Deploy via SFTP
  uses: appleboy/scp-action@master
  with:
    host: ${{ secrets.HOST }}
    username: ${{ secrets.USER }}
    key: ${{ secrets.SSH_PRIVATE_KEY }}
    source: "dist/*"
    target: "/var/www/html"
				
			

Common SFTP Errors & Fixes (2025–2026)

  1. Permission denied: Check remote directory ownership/permissions (ls -ld), use chown/chmod.
  2. Connection refused/timed out: Verify SSH service running (systemctl status ssh), port open, firewall allows 22.
  3. Host key verification failed: Remove old key from ~/.ssh/known_hosts or use -o StrictHostKeyChecking=no (not recommended for production).
  4. Subsystem request failed: Ensure Subsystem sftp line is correct in sshd_config; restart SSH.
  5. Broken pipe / connection closed: Check MTU, network stability, or server resource limits.

How to Use SFTP – FAQ (2025–2026)

  1. What is SFTP and why learn how to use SFTP instead of FTP? 
    SFTP is encrypted (via SSH), secure file transfer; FTP is plain-text and insecure. Mastering how to use SFTP ensures safe transfers in modern environments.

  2. How do I connect when learning how to use SFTP from the command line? 
    Use sftp user@host (or add -oPort=2222 for a custom port). This is the first step in how to use SFTP effectively.
  3. How to upload a folder when you’re figuring out how to use SFTP? 
    Run put -r local-folder (recursive). This command is essential when learning how to use SFTP for directory uploads.
  4. How to download all files in a directory while mastering how to use SFTP? 
    Use get -r remote-folder. Recursive downloads are a core part of how to use SFTP for bulk transfers.
  5. Can SFTP preserve file permissions, and how does that fit into how to use SFTP? 
    Yes: use get -p / put -p or -Pr for recursive operations. Preserving permissions is a key skill in how to use SFTP professionally.
  6. How to restrict a user to SFTP only (no SSH shell) while implementing how to use SFTP securely? 
    Add ChrootDirectory and ForceCommand internal-sftp in sshd_config. This locked-down setup is a best practice when learning how to use SFTP for restricted access.
  7. What port does SFTP use? 
    Port 22 (same as SSH). This is the default port you’ll always work with when discovering how to use SFTP.

Summary

You now know exactly how to use SFTP to securely transfer files, navigate, manage permissions, and integrate into modern workflows. Prefer SFTP over FTP/SCP for its encryption, flexibility, and compatibility. Always use SSH keys and restrict access for maximum security.

Recommended Resources

  • How To Enable SFTP Without Shell Access (Chroot Setup)
  • How To Use SSHFS to Mount Remote Directories
  • How To Use rsync Over SSH for Efficient Sync
  • SSH Key Best Practices 2025–2026