Securely transfer files between systems

4. Operate Running Systems

πŸ“˜Red Hat Certified System Administrator (RHCSA – EX200)


In the RHCSA exam, you must know how to transfer files securely between Linux systems. This is a very important skill for system administrators.

In IT environments, administrators often:

  • Copy configuration files to remote servers
  • Transfer backup files
  • Send log files for troubleshooting
  • Move application files between servers

For the exam, you must know how to securely transfer files using tools based on SSH (Secure Shell).


1. Understanding SSH (Secure Shell)

The most important service for secure file transfer is:

πŸ”Ή OpenSSH

SSH provides:

  • Encrypted communication
  • Secure remote login
  • Secure file transfer

SSH runs on:

  • Default port: 22
  • Service name: sshd

Check if SSH service is running:

systemctl status sshd

Start and enable SSH:

systemctl start sshd
systemctl enable sshd

Check firewall allows SSH:

firewall-cmd --list-services

If not allowed:

firewall-cmd --add-service=ssh --permanent
firewall-cmd --reload

For RHCSA, make sure:

  • SSH service is running
  • Firewall allows SSH

2. Secure File Transfer Methods

You must know the following commands:

  1. scp
  2. sftp
  3. rsync (over SSH)

All of them use SSH encryption.


3. Using scp (Secure Copy)

What is scp?

scp = Secure Copy
It copies files securely between systems using SSH.


Basic Syntax

scp source destination

Copy File From Local to Remote

scp file.txt user@remote_host:/home/user/

Example (IT environment):

scp backup.tar admin@192.168.1.10:/backup/

This:

  • Encrypts the data
  • Sends it securely
  • Places it in /backup/ directory

Copy File From Remote to Local

scp user@remote_host:/home/user/file.txt .

The . means current directory.


Copy a Directory

Use -r option:

scp -r mydir user@remote_host:/home/user/

Use Different SSH Port

scp -P 2222 file.txt user@remote_host:/home/user/

Important:

  • -P (capital P) for port

4. Using sftp (Secure FTP)

What is sftp?

sftp = Secure File Transfer Protocol
It works like FTP but is secure because it uses SSH.


Connect to Remote System

sftp user@remote_host

After login, you get:

sftp>

Important sftp Commands

CommandPurpose
lsList remote files
pwdShow remote directory
lpwdShow local directory
cdChange remote directory
lcdChange local directory
put fileUpload file
get fileDownload file
exitQuit

Upload File

put file.txt

Download File

get file.txt

5. Using rsync (Secure and Efficient Transfer)

rsync is very important in IT environments.

It is used for:

  • Backups
  • Synchronizing directories
  • Large data transfers

It transfers only changed data, not entire files again.


Basic Syntax

rsync options source destination

Copy Directory to Remote System

rsync -av /data/ user@remote_host:/backup/data/

Common Options:

OptionMeaning
-aArchive mode (preserves permissions, ownership)
-vVerbose
-zCompress data during transfer
-hHuman readable

Example with compression:

rsync -avz /project/ admin@192.168.1.20:/project_backup/

Important Exam Point

To use SSH explicitly:

rsync -av -e ssh /data user@remote:/backup

Most systems use SSH by default.


6. SSH Key-Based Authentication (Very Important for RHCSA)

By default, SSH uses passwords.

But secure environments use key-based authentication.

Advantages:

  • More secure
  • No password typing
  • Used in automation

Step 1: Generate SSH Key

ssh-keygen

It creates:

  • Private key: ~/.ssh/id_rsa
  • Public key: ~/.ssh/id_rsa.pub

Step 2: Copy Public Key to Remote System

ssh-copy-id user@remote_host

This adds your public key to:

~/.ssh/authorized_keys

Now you can connect without password:

ssh user@remote_host

And scp, sftp, rsync will also work without password.


7. File Permissions and Ownership During Transfer

Very important for exam.

When transferring files:

  • scp may not preserve ownership by default
  • rsync -a preserves:
    • permissions
    • ownership
    • timestamps

If permission problems occur:

chmod
chown

Always check:

ls -l

8. Security Best Practices for Exam

You must understand:

1. Never use plain FTP

FTP is not encrypted.

2. Always use SSH-based tools

  • scp
  • sftp
  • rsync over SSH

3. Restrict SSH Access

Edit:

/etc/ssh/sshd_config

Common secure settings:

  • Disable root login: PermitRootLogin no
  • Allow only specific users: AllowUsers admin

Restart SSH after changes:

systemctl restart sshd

9. Troubleshooting Secure Transfers

If connection fails:

Check:

systemctl status sshd

Check firewall:

firewall-cmd --list-all

Check port:

ss -tulnp | grep ssh

If permission denied:

Check:

  • File ownership
  • Directory permissions
  • SSH key permissions (must be strict)

Correct SSH permissions:

chmod 700 ~/.ssh
chmod 600 ~/.ssh/authorized_keys

10. What You Must Be Able to Do in the RHCSA Exam

You may be asked to:

  • Transfer a file securely to another system
  • Copy a directory securely
  • Use scp correctly
  • Use rsync to synchronize directories
  • Configure SSH key-based authentication
  • Troubleshoot SSH access problems
  • Ensure SSH service is running
  • Adjust firewall to allow SSH
  • Preserve permissions while copying files

You must be comfortable typing commands without help.


Quick Command Summary (Exam Revision)

Start SSH

systemctl start sshd

Enable SSH

systemctl enable sshd

Copy File

scp file user@host:/path

Copy Directory

scp -r dir user@host:/path

Use rsync

rsync -avz source user@host:/dest

Use sftp

sftp user@host

Generate SSH Key

ssh-keygen

Copy SSH Key

ssh-copy-id user@host

Final Exam Advice

For RHCSA:

  • Practice on two virtual machines.
  • Practice transferring files both ways.
  • Practice fixing SSH issues.
  • Practice using rsync with -a.
  • Understand how SSH and firewall work together.
  • Work confidently in terminal only (no GUI).

If you can securely transfer files using scp, sftp, and rsync, configure SSH keys, and troubleshoot problems β€” you are fully prepared for this exam section.

Buy Me a Coffee