Day 14 Learnings: Remote Access and File Transfers in Linux

Today's Linux journey focused on remote access and secure file transfers, essential skills for managing servers and transferring data over networks securely. I explored the ssh command for remote server connections and the scp command for copying files between systems.


What I Learned This Week

  • Using the ssh Command:
    Securely connect to a remote server via the command line.

  • Using the scp Command:
    Transfer files between local and remote systems securely.


Steps I Followed

Connecting to a Remote Server | ssh Command

  1. Basic SSH Connection:
    Connected to a remote server using its username and IP address:

     ssh user@remote-server-ip
    
  2. Specify a Port for SSH:
    Connected to a server running SSH on a non-default port (e.g., 2222):

     ssh -p 2222 user@remote-server-ip
    
  3. Copy SSH Public Key to Server:
    Set up key-based authentication for passwordless login:

     ssh-copy-id user@remote-server-ip
    
  4. Run Commands on a Remote Server:
    Executed a single command on the remote server without opening an interactive shell:

     ssh user@remote-server-ip 'ls -la'
    

Secure File Transfer | scp Command

  1. Copy File to a Remote Server:
    Transferred a file to the remote server's home directory:

     scp file.txt user@remote-server-ip:/home/user/
    
  2. Copy File from a Remote Server:
    Retrieved a file from the remote server to the local system:

     scp user@remote-server-ip:/home/user/file.txt /local/directory/
    
  3. Copy a Directory Recursively:
    Transferred a directory and its contents to a remote server:

     scp -r /local/directory user@remote-server-ip:/remote/directory/
    
  4. Specify an SSH Port for SCP:
    Used a custom SSH port for secure file transfer:

     scp -P 2222 file.txt user@remote-server-ip:/home/user/
    

Problems I Encountered

  1. Permission Denied During SSH Login:
    Could not log in due to missing permissions on the SSH key.

  2. Slow File Transfers with SCP:
    Large files took longer to transfer, causing delays.


How I Solved These Problems

  1. Fixing SSH Permissions:
    Adjusted permissions on the SSH private key:

     chmod 600 ~/.ssh/id_rsa
    
  2. Using Compression in SCP:
    Enabled compression during file transfer to speed up the process:

     scp -C file.txt user@remote-server-ip:/home/user/
    

Resources I Used

  • Linuxize Guide to SSH Command

  • Linuxize Guide to SCP Command

  • Forums for troubleshooting SSH key permissions and SCP optimizations.


Conclusion

Today’s topics provided insights into connecting to remote servers securely using SSH and transferring files efficiently with SCP. These tools are invaluable for managing remote systems and handling data securely.

Excited to delve into more Linux topics tomorrow in Day 15!