- Posted on
- • Software
sftp: Interactive file transfer over SSH
- Author
-
-
- User
- Linux Bash
- Posts by this author
- Posts by this author
-
Mastering SFTP: Your Guide to Secure File Transfers Over SSH
In the world of server management and secure file transfers, SFTP (SSH File Transfer Protocol) stands out as an essential tool for anyone who needs to securely transfer files between different machines. Unlike its predecessor FTP, SFTP encodes both commands and data, providing an added layer of security through its reliance on SSH (Secure Shell) to establish a secure connection.
For sysadmins, DevOps, or anyone managing remote servers, knowing how to use SFTP effectively is crucial. In this blog, we’ll explore what SFTP is, how to use it, and most importantly, how to install it on various Linux distributions.
What is SFTP?
SFTP is a protocol used for transferring files securely over a network. It operates over SSH, which means that the transfer is encrypted and authenticated, significantly reducing the risk of data being intercepted or tampered with. SFTP also allows for a range of operations not just limited to file transfer, including permission and attribute manipulation, file locking, and more complex directory listings.
Installing SFTP
SFTP typically comes bundled with SSH packages, so installing it usually involves setting up an SSH server. Here's how to install SSH (and consequently SFTP) on different Linux distributions using various package managers:
For Debian and Ubuntu systems:
Debian-based systems use apt
for package management. To install SSH (including SFTP), open your terminal and run the following commands:
sudo apt update
sudo apt install openssh-server
After installing, the SSH service should start automatically. You can check its status with:
sudo systemctl status ssh
For Fedora, CentOS, and RHEL systems:
These systems use dnf
(or yum
on older versions). To install SSH, use the following commands:
sudo dnf update
sudo dnf install openssh-server
Like with apt
, you can check the status of the SSH service using:
sudo systemctl status ssh
For openSUSE:
On openSUSE, zypper
is the package manager. Install SSH using these commands:
sudo zypper refresh
sudo zypper install openssh
And again, check the service status with:
sudo systemctl status sshd
How to Use SFTP
Once you have SSH and SFTP installed, you can begin transferring files securely. Here’s a simple guide on how to start an SFTP session from the command line:
Connect to the Server: Open your terminal and connect to the server using the following syntax:
sftp username@host
Replace
username
with your actual username on the server andhost
with the server's IP address or domain name.Transfer Files:
- To upload a file from your local machine to the server, use:
bash put localfilepath
- To download a file from the server to your local machine, use:
bash get remotefilepath
- To upload a file from your local machine to the server, use:
Navigating Directories:
- To change directory on your local machine, use:
bash lcd directorypath
- To change directory on the server, use:
bash cd directorypath
- To change directory on your local machine, use:
Listing Files: To list the files in the current directory on the server, simply use:
ls
Exiting SFTP: When you’re done, type:
exit
Conclusion
Learning to use SFTP is essential for managing files on remote servers securely. Whether you’re a developer, a system administrator, or just a tech enthusiast, mastering SFTP can greatly streamline the way you handle file transfers in a secure manner. Following the installation and usage guides above should set you on the right path toward leveraging this powerful tool in your everyday tasks.