π Linux/Unix: Transfers & Access β ssh
, scp
, rsync
, sftp
Explained with Examples
π§² Introduction β Why Learn Secure Transfers & Access in Linux?
In Linux and Unix systems, remote access and file transfers are essential for system administration, backups, scripting, and DevOps. Tools like ssh
, scp
, rsync
, and sftp
enable you to connect securely, transfer data, and synchronize files over networksβall encrypted via SSH.
π― In this guide, youβll learn:
- How to securely connect to remote machines using
ssh
- How to transfer files with
scp
,rsync
, andsftp
- The differences, use cases, and output of each tool
π 1. ssh
β Secure Remote Shell Access
β
What is ssh
?
ssh
(Secure Shell) allows you to log in to remote systems securely over an encrypted channel.
π οΈ Syntax:
ssh [user@]hostname [command]
π§ͺ Example 1: Login to a remote machine
ssh user@192.168.1.100
π€ Output:
user@192.168.1.100's password:
Welcome to Ubuntu 22.04 LTS ...
π§ͺ Example 2: Run a command remotely
ssh user@192.168.1.100 uptime
π€ Output:
14:23:01 up 10 days, 5:12, 2 users, load average: 0.15, 0.09, 0.05
π€ 2. scp
β Secure Copy Over SSH
β
What is scp
?
scp
securely transfers files between local and remote systems using SSH.
π οΈ Syntax:
scp [options] source destination
π§ͺ Example 1: Copy a file to remote server
scp file.txt user@192.168.1.100:/home/user/
π§ͺ Example 2: Copy a remote file to local system
scp user@192.168.1.100:/var/log/syslog /tmp/
π§ Common Flags:
Flag | Description |
---|---|
-r | Recursive copy (for dirs) |
-P | Use custom port |
-v | Verbose output |
π 3. rsync
β Efficient Synchronization Tool
β
What is rsync
?
rsync
is used to synchronize files and directories between local and remote systems. It transfers only differences, making it fast and efficient.
π οΈ Syntax:
rsync [options] source destination
π§ͺ Example 1: Sync local directory to remote
rsync -avz /etc/ user@192.168.1.100:/backup/etc/
π€ Output:
sending incremental file list
etc/
etc/passwd
etc/hostname
sent 4,095 bytes received 82 bytes total size 3,512
π§ Common Flags:
Flag | Description |
---|---|
-a | Archive (preserve all) |
-v | Verbose |
-z | Compress during transfer |
--delete | Delete extra files on dest |
π 4. sftp
β Interactive File Transfer over SSH
β
What is sftp
?
sftp
provides an interactive shell to transfer files using the SSH File Transfer Protocol.
π οΈ Syntax:
sftp [user@]host
π§ͺ Example 1: Start SFTP session
sftp user@192.168.1.100
π€ Output:
Connected to 192.168.1.100.
sftp>
π§ͺ Example 2: Upload and download files
Inside sftp>
shell:
put localfile.txt
get remotefile.log
π§ Common SFTP Commands:
Command | Description |
---|---|
ls | List remote files |
lcd | Change local dir |
cd | Change remote dir |
put | Upload file |
get | Download file |
exit | Exit sftp shell |
βοΈ Comparison Table: ssh vs scp vs rsync vs sftp
Tool | Purpose | Supports SSH | Interactivity | Best For |
---|---|---|---|---|
ssh | Remote command execution | β | β | Login and shell commands |
scp | Secure file copy | β | β | Simple file transfers |
rsync | Efficient file synchronization | β | β | Backups and incremental syncs |
sftp | Interactive file transfers | β | β | Manual uploads/downloads |
π Summary β Recap & Next Steps
These Linux tools make it easy to remotely access systems, transfer files securely, and sync data across environments. They’re built on SSH, ensuring encrypted communication.
π Key Takeaways:
- Use
ssh
to log into remote systems or run remote commands - Use
scp
for quick file copying over SSH - Use
rsync
for efficient, repeatable file backups and sync - Use
sftp
for interactive file uploads/downloads
β FAQs
β Is scp
faster than rsync
?
β No. rsync
is faster for large or repeat transfers due to delta-copying.
β Can I resume interrupted scp
transfers?
β Not natively. Use rsync
instead:
rsync --partial --progress file user@host:/path/
β How can I change ports in ssh
, scp
, or rsync
?
β
Use -p
for ssh
/scp
, and -e 'ssh -p PORT'
for rsync
.
β Which one supports GUI alternatives?
β
sftp
can be used via GUI tools like FileZilla, WinSCP, or Cyberduck.
β Is it secure to use these tools over the internet?
β
Yes, if using SSH keys and disabling password authentication for added security.
Share Now :