Voiced by Amazon Polly |
Introduction
Some of the benefits of SFTP are:
- Secure File Transfer – SFTP is primarily used for securely transferring files between systems over an insecure network, such as the internet. It ensures that data remains confidential and protected from unauthorized access during transit.
- Remote Server Administration – SFTP is commonly used by system administrators to remotely manage servers. They can securely upload, download, and modify files on the server, perform backups, update configurations, and execute administrative tasks.
- Website Maintenance – SFTP is often employed by web developers and designers to update and maintain websites hosted on remote servers. It allows them to upload new files, modify existing ones, and manage the website’s directory structure securely.
- Automated File Transfers – SFTP can be integrated into automated workflows and scripts, allowing for the scheduled or event-driven transfer of files between systems. This is useful for tasks like data backups, synchronizing files between servers, and distributing files to multiple locations.
- Secure Data Exchange – Organizations that need to exchange sensitive data with external partners, clients, or suppliers can utilize SFTP to ensure the secure transfer of files. SFTP’s encryption and authentication mechanisms provide a higher level of security compared to traditional FTP.
- Cloud Storage Integration – Many cloud storage providers support SFTP as a method for securely accessing and transferring files to and from cloud storage. This enables users to interact with their cloud-based files using SFTP clients, providing an additional layer of security.
Pioneers in Cloud Consulting & Migration Services
- Reduced infrastructural costs
- Accelerated application deployment
Step-by-Step Guide
Step 1: Set up an SFTP directory on a Linux server
In the below scenario, we are using Ubuntu 20.4 server hosted on Azure.
We will create a directory named ‘data’ under / directory with full owner permissions, group no permissions, and others only execute permission.
1 2 |
mkdir -p /data chmod 701 /data |
Step 2: Create an SFTP group and user
Now we will create a group named ‘sftp_users’ and add the user ‘YOURUSERNAME’ to group ‘sftp_users’ only for sftp.
Run the below commands for the same
1 2 3 |
groupadd sftp_users useradd -g sftp_users -d /upload -s /sbin/nologin YOURUSERNAME passwd YOURUSERNAME |
Step 3: Set up a new user SFTP directory
Now, we will create a directory ‘YOURUSERNAME/upload’ under ‘/data’ directory with user ‘root’ as the owner and ‘sftp_users’ group as the group for directory /data/YOURUSERNAME.
user ‘YOURUSERNAME’ as owner and ‘sftp_users’ group as the group for directory /data/YOURUSERNAME/upload
Run the below commands for the same.
1 2 3 |
mkdir -p /data/YOURUSERNAME/upload chown -R root:sftp_users /data/YOURUSERNAME chown -R YOURUSERNAME:sftp_users /data/YOURUSERNAME/upload |
Step 4: Configure sshd using the below command
1 2 3 4 5 |
vi /etc/ssh/sshd_config Add the below lines at the bottom of the file Match Group sftp_users ChrootDirectory /data/%u ForceCommand internal-sftp |
Step 5: Save the File and run the below command to restart the sshd service
1 2 |
systemctl restart sshd systemctl status sshd |
Step 6: Logging in
From a different machine on your network that has SSH installed, open a new terminal window and run the below command:
1 |
sftp YOURUSERNAME@SERVER_IP |
Step 7: Upload a file
Now, let’s upload a ‘test’ file to sftp server using PUT command.
1 |
put filepath\filename |
Verify our upload by browsing to the sftp directory, which we created in Step 3
Conclusion
This blog shows how to set up an SFTP server and transfer files securely from a local machine to a remote server using the SFTP protocol.
Other alternative file transfer clients using SSH besides CLI are SCP, FileZilla, etc.
Ensure Excellence Without Compromise Through CloudThat's DevSecOps Services
- Rapid deployment
- Automate user creation
- Reduced time to market
About CloudThat
CloudThat is an official AWS (Amazon Web Services) Advanced Consulting Partner and Training partner and Microsoft Gold Partner, helping people develop knowledge of the cloud and help their businesses aim for higher goals using best in industry cloud computing practices and expertise. We are on a mission to build a robust cloud computing ecosystem by disseminating knowledge on technological intricacies within the cloud space. Our blogs, webinars, case studies, and white papers enable all the stakeholders in the cloud computing sphere.
Drop a query if you have any questions regarding SFTP, Linux Server and I will get back to you quickly.
To get started, go through our Consultancy page and Managed Services Package that is CloudThat’s offerings.
FAQs
1. What does SFTP stand for?
ANS: – SFTP stands for Secure File Transfer Protocol which uses SSH port 22 to transfer the file to a remote server.
2. What if SSH is not installed or not enabled?
ANS: – Install the ‘openssh-server’ package on Ubuntu by running the below command.
1 |
sudo apt install openssh-server |
1 |
sudo systemctl enable ssh |
1 |
sudo ufw allow ssh |
3. What are other SFTP commands available?
ANS: – Some of the basic commands are mentioned below-
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 |
sftp> put to Upload file sftp> get to Download file sftp> cd path to Change remote directory to ‘path’ sftp> pwd to Display remote working directory sftp> lcd path Change the local directory to ‘path’ sftp> lpwd Display local working directory sftp> ls Display the contents of the remote working directory sftp> lls |
WRITTEN BY Sumeet Agarwal
Click to Comment