Linux sftp command with Example
Last Updated :
04 Nov, 2023
In this article, we are going discuss about sftp. It is a protocol for securely transferring files from a remote server to a local machine. before SFTP, FTP was used to transfer files but it was unsecured. An attacker can read the communication between a remote server and a local machine.
What is SFTP?
SFTP stands for Secure File Transfer Protocol. It is a secure and efficient method for transferring files in the Linux environment. It is a command-line tool used in mostly Linux, UNIX-based operating systems. It is an extension of SSH(Secure Shell) and encrypts the command and data during transmission.
Advantages of SFTP
- SFTP ensures that it encrypts the data and commands.
- SFTP checks the data integrity, and whether any data is tampered with or lost during transmission.
- SFTP checks the user authentication with a valid username and password.
- SFTP supports most of the operating systems, which makes them portable to use.
- SFTP is user-friendly, it is easy to use either in command line or graphical mode.
- SFTP allows their command for scripting and automation.
- SFTP allows multiple users to access and transfer the file securely.
The syntax for `SFTP` command in Linux
sftp username@ip_address/hostname
Here,
sftp: It is a utility used for connecting ftp servers securely.
username: Mention the username for connecting to ftp server.
ip_address/hostname: Mention the IP address of the remote server or machine name.
Options available for SFTP
Gives the name of a batch file that contains SFTP commands.
|
Determines the size of the file transmission buffer.
|
Specifies the remote host’s port to use for the connection.
|
For verbose mode, it generate the detailed report
|
It displays the helps information for particular command
|
Prints the current working directory
|
Change the directory
|
It is used to download the file from remote server
|
It is used to upload the file in remote server
|
It removes a file from the distant server
|
It create a directory in remote server
|
It remove the directory from remote server
|
It sets the permissions on files and directories
|
Examples of SFTP
For connecting to remote server, we need to provide the username and ip address
username: testuser1
ip address: 192.168.28.232
sftp testuser1@192.168.29.232
To view the current working directory in remote server
pwd
Create a directory in remote server
mkdir directory1
Remove the directory from remote server
rmdir dir1
To download the file from remote server to local machine
get geek.txt /home/kali
To delete/remove the file from remote server
rm ftp/test/demo.txt
To upload the file from local machine to remote server
put /home/kali/abc.txt /home/testuser1/ftp
Specify the buffer size that uses sftp when transferring the files
sftp -B 4096 testuser1@192.168.29.232
Table of Differences between FTP vs SFTP
No encryption is applied during transmission.
|
Proper encryption is applied during transmission.
|
Uses two port 20 & 21 for data transmission
|
Uses single port 22 for data transmission
|
No built-in encryption
|
SSH implies for data encryption.
|
It uses username and password in a plain text for authentication.
|
It uses various authentication method like SSH key.
|
It doesn’t check if any data is tampered or lost
|
It checks the data if any data is tampered or lost.
|
It supports many operating system like Linux, UNIX or Windows.
|
It supports only Linux and UNIX operating system.
|
It requires additional ports to be allowed in firewall rules.
|
It requires only single port to be allowed in firewall rules.
|
FileZilla, WinSCP
|
OpenSSH, PuTTY
|
Top 5 Frequently Asked Questions(FAQs)
1. What is sftp in Linux, and how does it differ from regular FTP?
Secure File Transfer Protocol is referred to as sftp. It is a Linux command-line utility for using the SSH (Secure Shell) protocol to send and receive files securely. SFTP Secure and private file transfers are made possible by the encryption of both commands and data, unlike ordinary FTP.
2. How do I connect to a remote server using sftp?
The command sftp username@ip_address is used to establish a connection to a remote server using SSH. Change “username” to the username you use on the remote server, and the IP address or hostname of the server. To make the connection, you will need to enter your password.
3. Can I use sftp without entering a password every time?
Yes, you can set up sftp to authenticate users using SSH keys. You can log in using this technique without having to input your password each time. When you create an SSH key pair and upload the public key to a remote server, sftp will use the key to verify your identity.
4. How do I upload and download files using sftp?
Use the put command to upload a file: put local_file_path remote_destination. Use the get command to download a file: get remote_file_path local_destination. These instructions securely move files from your local system to the destination server.
5. What are some common sftp commands for managing files and directories?
Common sftp commands include put (upload file), get (download file), ls (list files), mkdir (create directory), rmdir (delete directory), and rm (remove file). You can browse and manage files on the remote server using these commands.
Conclusion
In a conclusion, SFTP command is a faster and secure tool for transferring the files between server and client. It also provides the security which helps in preventing the cyber attacks. As we have already discuss about sftp features and its usability.
Share your thoughts in the comments
Please Login to comment...