Securely Transfer Files Over the Private Network Using SCP or Rsync

Introduction

When using commands like scp or rsync with the public IP address of your server, you will automatically transfer the files over the (public) internet. If you have have two instances with private networking enabled you can also transfer these files over the private network and prevent extra charges for the used bandwidth.

Prerequisites

  • Two instances (we'll call them server_a and server_b) with private networking enabled
  • Both instances should have private IP addresses configured in the same subnet (see Configuring Private Network)
  • SSH connectivity should be possible between both instances
  • A user which is not root (we'll call it your_user)

Generating and using SSH keys

Transferring files is possible using username and password authentication, but it's much safer to use SSH keys. The generation of the public-private key is described in How Do I Generate SSH Keys?. If you decide to skip this section then you'll have to enter the remote user's password in every command.

Assuming that the public-private key pair on server_a is located in ~/.ssh/id_rsa, you can run the following command to transfer your public key to server_b. Use the private IP address of server_b.

ssh-copy-id your_user@192.168.0.101

When prompted, give the password for your_user.

ssh-copy-id your_user@192.168.0.101 /usr/bin/ssh-copy-id: INFO: Source of
key(s) to be installed: "/home/your_user/.ssh/id_rsa.pub" The
authenticity of host '192.168.0.101 (192.168.0.101)' can't be
established. ECDSA key fingerprint is
SHA256:g9dfqycqU25b567/HDjPTqaQqKhep/fysNCQAG9yJG4. ECDSA key
fingerprint is MD5:41:67:be:68:51:9b:38:a8:95:82:71:47:f1:35:39:66.
Are you sure you want to continue connecting (yes/no)? yes
/usr/bin/ssh-copy-id: INFO: attempting to log in with the new key(s),
to filter out any that are already installed /usr/bin/ssh-copy-id:
INFO: 1 key(s) remain to be installed -- if you are prompted now it is
to install the new keys your_user@192.168.0.101's password:

Number of key(s) added: 1

Now try logging into the machine.

ssh your_user@192.168.0.101

Check to make sure that only the key(s) you wanted were added.

If you now SSH from server_a to server_b, it will no longer ask for a password. In case the public-private key pair is not located in ~/.ssh/id_rsa then you can specify it's location with the -i parameter (you will also need this parameter with the scp and rsync command).

ssh-copy-id -i /path/to/your/public_key your_user@192.168.0.101 
ssh -i /path/to/your/private_key your_user@192.168.0.101 

Transferring files with SCP

SCP stands for Secure Copy and it transfers all data over an SSH connection. To copy a single file, ~/myfile, from server_a to the /tmp directory on server_b we can issue the following command.

scp ~./myfile your_user@192.168.0.101:/tmp

To copy a complete folder with all it's contents (including symbolic links) you can add the -r option

scp -r ~./mydir your_user@192.168.0.101:/tmp

Transferring files with Rsync

Rsync is a versatile tool to copy files, it's most often used to synchronize the content of two locations. It uses the same secure SSH tunnel to transfer data. A complete folder can be synchronized to a remote /tmp dir with the following command

rsync -av ~/mydir your_user@192.168.0.101:/tmp

The -v option increases verbosity so that you can follow the progress of the transfer. The -a option enables 'archive mode' which copies your files recursively while preserving attributes like owner, group and permissions.

Dejar un comentario

ZPanel y Sentora en CentOS 6 x64

ZPanel y Sentora en CentOS 6 x64

ZPanel, un panel de control de alojamiento web popular, se bifurcó en 2014 a un nuevo proyecto llamado Sentora. Aprende a instalar Sentora en tu servidor con este tutorial.

Cómo instalar Vtiger CRM Open Source Edition en CentOS 7

Cómo instalar Vtiger CRM Open Source Edition en CentOS 7

Aprende cómo instalar Vtiger CRM, una aplicación de gestión de relaciones con el cliente, en CentOS 7 para aumentar tus ventas y mejorar el servicio al cliente.

Cómo instalar el servidor Counter-Strike 1.6 en Linux

Cómo instalar el servidor Counter-Strike 1.6 en Linux

Esta guía completa le mostrará cómo configurar un servidor Counter-Strike 1.6 en Linux, optimizando el rendimiento y la seguridad para el mejor juego. Aprende los pasos más recientes aquí.

¿Puede la IA luchar con un número cada vez mayor de ataques de ransomware?

¿Puede la IA luchar con un número cada vez mayor de ataques de ransomware?

Los ataques de ransomware van en aumento, pero ¿puede la IA ayudar a lidiar con el último virus informático? ¿Es la IA la respuesta? Lea aquí, sepa que la IA es una bendición o una perdición

ReactOS: ¿Es este el futuro de Windows?

ReactOS: ¿Es este el futuro de Windows?

ReactOS, un sistema operativo de código abierto y gratuito, está aquí con la última versión. ¿Puede satisfacer las necesidades de los usuarios de Windows de hoy en día y acabar con Microsoft? Averigüemos más sobre este estilo antiguo, pero una experiencia de sistema operativo más nueva.

Manténgase conectado a través de la aplicación de escritorio WhatsApp 24 * 7

Manténgase conectado a través de la aplicación de escritorio WhatsApp 24 * 7

Whatsapp finalmente lanzó la aplicación de escritorio para usuarios de Mac y Windows. Ahora puede acceder a Whatsapp desde Windows o Mac fácilmente. Disponible para Windows 8+ y Mac OS 10.9+

¿Cómo puede la IA llevar la automatización de procesos al siguiente nivel?

¿Cómo puede la IA llevar la automatización de procesos al siguiente nivel?

Lea esto para saber cómo la Inteligencia Artificial se está volviendo popular entre las empresas de pequeña escala y cómo está aumentando las probabilidades de hacerlas crecer y dar ventaja a sus competidores.

La actualización complementaria de macOS Catalina 10.15.4 está causando más problemas que resolver

La actualización complementaria de macOS Catalina 10.15.4 está causando más problemas que resolver

Recientemente, Apple lanzó macOS Catalina 10.15.4, una actualización complementaria para solucionar problemas, pero parece que la actualización está causando más problemas que conducen al bloqueo de las máquinas Mac. Lee este artículo para obtener más información

13 Herramientas comerciales de extracción de datos de Big Data

13 Herramientas comerciales de extracción de datos de Big Data

13 Herramientas comerciales de extracción de datos de Big Data

¿Qué es un sistema de archivos de diario y cómo funciona?

¿Qué es un sistema de archivos de diario y cómo funciona?

Nuestra computadora almacena todos los datos de una manera organizada conocida como sistema de archivos de diario. Es un método eficiente que permite a la computadora buscar y mostrar archivos tan pronto como presiona buscar.