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 a leading provider of Cloud Training and Consulting services with a global presence in India, the USA, Asia, Europe, and Africa. Specializing in AWS, Microsoft Azure, GCP, VMware, Databricks, and more, the company serves mid-market and enterprise clients, offering comprehensive expertise in Cloud Migration, Data Platforms, DevOps, IoT, AI/ML, and more.
CloudThat is the first Indian Company to win the prestigious Microsoft Partner 2024 Award and is recognized as a top-tier partner with AWS and Microsoft, including the prestigious ‘Think Big’ partner award from AWS and the Microsoft Superstars FY 2023 award in Asia & India. Having trained 850k+ professionals in 600+ cloud certifications and completed 500+ consulting projects globally, CloudThat is an official AWS Advanced Consulting Partner, Microsoft Gold Partner, AWS Training Partner, AWS Migration Partner, AWS Data and Analytics Partner, AWS DevOps Competency Partner, AWS GenAI Competency Partner, Amazon QuickSight Service Delivery Partner, Amazon EKS Service Delivery Partner, AWS Microsoft Workload Partners, Amazon EC2 Service Delivery Partner, Amazon ECS Service Delivery Partner, AWS Glue Service Delivery Partner, Amazon Redshift Service Delivery Partner, AWS Control Tower Service Delivery Partner, AWS WAF Service Delivery Partner, Amazon CloudFront Service Delivery Partner, Amazon OpenSearch Service Delivery Partner, AWS DMS Service Delivery Partner, AWS Systems Manager Service Delivery Partner, Amazon RDS Service Delivery Partner, AWS CloudFormation Service Delivery Partner, AWS Config, Amazon EMR and many more.
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
Comments