How to Start an Interactive SFTP Session on Ubuntu
Secure File Transfer Protocol (SFTP) is a secure method used to transfer files between a local computer and a remote Ubuntu Linux server over an encrypted SSH connection. This guide provides a straightforward, step-by-step tutorial on how to initiate an interactive SFTP session from your terminal, authenticate with your server, and use essential commands to manage your files.
Prerequisites
Before you begin, ensure you have the following: * A remote Ubuntu server with SSH enabled. * The IP address or domain name of the Ubuntu server. * Your SSH username and password (or SSH private key). * A terminal application (on Linux/macOS) or Command Prompt/PowerShell (on Windows 10/11).
Step 1: Open Your Terminal
Open your local command-line interface. Since SFTP runs over SSH, you
do not need to install any additional software; the standard
sftp client is pre-installed on almost all modern operating
systems.
Step 2: Run the SFTP Command
To initiate the connection, use the sftp command
followed by your remote username and the server’s IP address or domain
name.
sftp username@remote_server_ipIf your SSH server uses a custom port (other than the default port
22), specify the port using the -P flag:
sftp -P custom_port username@remote_server_ipIf you authenticate using an SSH private key instead of a password,
use the -i flag to point to your key file:
sftp -i /path/to/private_key username@remote_server_ipStep 3: Authenticate with the Server
If this is your first time connecting to the server, your terminal
will display a message asking you to verify the authenticity of the
host. Type yes and press Enter to
continue.
Next, you will be prompted for credentials: * If using password authentication, type your password and press Enter (the characters will not appear on the screen as you type). * If using a key file protected by a passphrase, enter the passphrase when prompted.
Once successfully authenticated, your terminal prompt will change to:
sftp>
This indicates that you are now in an active, interactive SFTP session.
Step 4: Essential SFTP Commands
Now that you are connected, you can navigate the directories and transfer files. The following commands will help you manage your interactive session:
- View current remote directory:
pwd - View current local directory:
lpwd - List files in the remote directory:
ls - List files in the local directory:
lls - Change remote directory:
cd /path/to/directory - Change local directory:
lcd /path/to/directory - Download a file from remote to local:
get filename - Upload a file from local to remote:
put filename
Step 5: Close the SFTP Session
Once you have finished transferring files, you can safely close the interactive session by typing either of the following commands:
sftp> exit
or
sftp> bye