What Is the .bashrc File in Linux?
The .bashrc file is a shell script that runs every time...
Secure file transfer between Linux systems is a routine part of system administration. Whether you’re deploying code to a production server, syncing configuration files across nodes, or pushing backups to a remote host, SSH-based tools are the standard choice. They provide encryption and authentication by default.
In this guide, we’ll transfer files between two Linux machines on the same network. Machine A (IP: 192.168.10.10, user: linuxuser) will act as the source or sender, while Machine B (IP: 192.168.10.8, user: ubuntu) will serve as the destination or receiver. We’ll demonstrate how to copy files in both directions using efficient command-line tools.
rsync (remote synchronization) is a command-line tool used on Unix-like systems to copy and sync files or folders between two machines. One machine acts as the source (local host), and the other is the destination (remote host). rsync uses SSH for secure communication and supports synchronization, compression, and differential updates.
Effortless Linux File Transfers with Ultahost VPS
Transfer files between Linux systems easily using Ultahost’s secure and high-performance Linux VPS. Enjoy reliable speed, full control, and ultaai support.
Run the following command to install rsync on both systems:
sudo apt install rsync -y
Since rsync uses SSH to transfer files, make sure each machine can SSH into the other. From Machine B (192.168.10.8), test SSH to Machine A using the following command:
ssh [email protected]
Now, from Machine A (192.168.10.10), test SSH to Machine B:
ssh [email protected]
If you’re prompted for a password and successfully log in, SSH is working.
To avoid typing your password every time, generate a key pair and copy it to the remote machine. Run the following command on the machine initiating the transfer (Press Enter through all prompts to use defaults.):
ssh-keygen -t rsa
Now, copy your public key to the destination machine:
ssh-copy-id [email protected]
Now, you can connect without typing a password.
Use rsync to copy a file from Machine B to Machine A:
rsync -avz /home/ubuntu/file.txt [email protected]:/home/linuxuser
Here, -a
preserves file attributes, -v
shows progress, and -z
compresses data to speed up the transfer:
To copy a folder from Machine A to Machine B, use the following command:
rsync -avz /home/linuxuser/docs/ [email protected]:/home/ubuntu/
Here, the trailing / ensures only the contents are copied, not the folder itself:
If you want to copy from Machine A to Machine B, just reverse the source and destination in the command:
rsync -avz [email protected]:/home/ubuntu/file.txt /home/linuxuser
FTP (File Transfer Protocol) is a common way to move files between computers over a TCP network, but it doesn’t use encryption by default. To transfer files, one system must act as the FTP server (using software like vsftpd), while the other connects to it as a client. Below are the steps to perform a simple FTP file transfer between two Linux machines.
Install vsftpd on the system acting as the server (e.g., Machine B):
sudo apt install vsftpd
Open port 21 so the server can receive FTP connections.
sudo ufw allow 21/tcp
Let’s create a file to test the upload:
echo "FTP test file" > /home/linuxuser/Documents/ftp-test.txt
From the client machine, connect using the following command:
ftp 192.168.10.8
Enter the username and password when prompted.
Once connected, upload the file by executing the following command:
put /home/linuxuser/Documents/ftp-test.txt ftp-test.txt
Use the following command to download the file from the FTP server:
get ftp-test.txt
Samba is mainly used to share files between Linux and Windows using the SMB/CIFS protocol. But in a Linux-to-Linux setup, it helps create shared folders that multiple systems can access with the right permissions. This is useful for teamwork or when systems need continuous access to shared files. The best way to transfer files with Samba is by mounting the shared folder using the “mount -t cifs” command. The steps below explain how to set up and use this method for file transfer.
Run the following command on both machines (A and B) to install Samba:
sudo apt install samba smbclient cifs-utils -y
Create a Shared Folder on Machine A using the mkdir command:
mkdir -p /home/linuxuser/shared
Then, give full permissions so other machines can read/write:
chmod 777 /home/linuxuser/shared
Now edit the Samba’s configuration file:
sudo nano /etc/samba/smb.conf
Paste the following code at the bottom of the file:
[SharedFolder] path = /home/linuxuser/shared available = yes valid users = linuxuser read only = no browsable = yes public = yes writable = yes
Set a password for the Samba user:
sudo smbpasswd -a linuxuser
Now, restart the Samba service:
sudo systemctl restart smbd
On Machine B (192.168.10.8), use smbclient to test:
smbclient //192.168.10.10/SharedFolder -U linuxuser
Enter the Samba password you set earlier. If it works, you’ll get an smb: prompt, where you can use commands like ls, get, and put to manage files.
For example, you can use the put command to upload a File to the FTP Server:
put /home/ubuntu/Documents/smb-test.txt smb-test.txt
Similarly, to download a File from the FTP Server, you can use the get command:
get smb-test.txt
To access the Samba shared folder as if it’s part of the local file system on Machine B, first create a directory to serve as the mount point:
mkdir -p /home/ubuntu/mountA
Next, mount the shared folder from Machine A using the following command:
sudo mount -t cifs //192.168.10.10/SharedFolder /home/ubuntu/mountA -o username=linuxuser,password=<SambaPassword>
Once mounted, you can check if the folder is accessible by listing its contents:
ls /home/ubuntu/mountA
To send a file from Machine B to the shared folder on Machine A, use the cp command:
sudo cp /home/ubuntu/smb-test.txt /home/ubuntu/mountA/
This file will now be available in /home/linuxuser/shared on Machine A. Use the cd command to access it:
To copy files from Machine A to Machine B, simply pull them from the mounted directory into your local folders, like this:
cp /home/ubuntu/mountA/filename.txt /home/ubuntu/
The scp command lets you copy files between two systems using SSH. It works much like the cp command, but instead of copying files within your local machine, it securely transfers them over the network. Both the data and login details are encrypted during the process. This makes scp a good choice for quick and straightforward file transfers when you don’t need a more advanced syncing tool like rsync.
To use scp, SSH must be installed and running on both machines. You can install it using the following commands:
sudo apt update && sudo apt install openssh-server -y
After installation, enable and start the SSH service on both machines so it starts automatically on boot:
sudo systemctl enable --now ssh && sudo systemctl status ssh
You should see it as active (running).
Before transferring files, test the SSH connection between the machines. From Machine A to Machine B:
ssh [email protected]
From Machine B to Machine A:
ssh [email protected]
If you’re prompted to enter a password and you successfully log in, then SSH is working properly.
To copy a file from Machine A to Machine B, use the following command on Machine A:
scp /path/to/localfile.txt [email protected]:/home/ubuntu/
Replace /path/to/localfile with actual file path:
scp /home/linuxuser/localfile.txt [email protected]:/home/ubuntu/
This sends the file localfile.txt
to the /home/ubuntu/ directory on Machine B:
To copy a file from Machine B to Machine A, run this command on Machine B:
scp /path/to/localfile.txt [email protected]:/home/linuxuser/
For example, the following command places the file into the /home/linuxuser/ directory on Machine A:
scp /home/ubuntu/text.txt [email protected]:/home/linuxuser/
If you want to copy a full folder, use the -r flag with scp to transfer it recursively. For instance, to transfer a directory from Machine A to Machine B, run the command:
scp -r /home/linuxuser/project [email protected]:/home/ubuntu/
Similarly, the following command copies all the contents of the directory, including subfolders and files, from Machine B to Machine A:
scp -r /home/ubuntu/docs [email protected]:/home/linuxuser/
SFTP (Secure File Transfer Protocol) is a safer version of FTP that works through SSH. It encrypts both the files and the commands sent during transfer, keeping the data private and secure. So, if SSH is enabled on your Linux systems, SFTP is a reliable way to move files between them.
Before using SFTP, make sure the SSH server is installed and running on the system you want to connect to (Machine B):
sudo apt update && sudo apt install openssh-server -y
SFTP uses port 22 by default, which must be open for connections. Run this command to allow traffic:
sudo ufw allow 22/tcp
From Machine A, initiate a connection to Machine B using the sftp command. Replace ubuntu with the username of Machine B:
sftp [email protected]
Enter the password for the user ubuntu when prompted:
Once connected, you’ll be inside an interactive SFTP session where you can send or receive files. Inside the SFTP prompt, use the following command to upload a file from Machine A to Machine B:
put /home/linuxuser/file.txt
Similarly, you can use the get command to download the files and folders:
get /home/ubuntu/file.txt
If you’re looking for a fast way to share files between two Linux systems without setting up SSH or additional tools, Python’s built-in HTTP server is a great option. This method is especially useful for temporary or one-time transfers over a local network.
Open a terminal on the machine that has the file you want to share. To do this, navigate to the folder containing the file(s) you want to transfer:
cd /path/to/files
Then start a simple HTTP server on port 8000 using Python:
python3 -m http.server 8000
This command launches a temporary web server that serves all files in the current directory:
You can now access and download the file from Machine B using either of the following methods. Open any browser and go to the following URL to access the directory content:
http://192.168.100.86:8000/
Just click the file you want to download.
Alternatively, if you prefer the command line, you can access it using the following command:
wget http://192.168.100.86:8000/web-share-sample.txt
If you want to send a file from Machine B to Machine A, simply switch the roles. On Machine B, run the command below:
python3 -m http.server 8000
Then, on Machine A, either open a browser and go to “http://192.168.100.88:8000/”, or download the file directly using the following command:
wget http://192.168.100.88:8000/file.txt
That’s all about transferring a file between two Linux systems.
Transferring files between Linux systems is a common task in both administration and development. In this guide, we explored several effective methods, including rsync for secure synchronization, FTP and Samba for network sharing, scp and SFTP for SSH-based transfers, and Python’s HTTP server for quick one-time sharing. Each method fits different needs, from regular backups to temporary file sharing. You can choose the method that best fits your needs to ensure smooth, secure, and efficient file transfers between your Linux machines.
Transferring files between two Linux systems becomes seamless with the right tools and environment. Ultahost’s affordable VPS hosting plans provide full root access, NVMe SSD storage, and a secure platform to help you move data efficiently between servers using SFTP, SCP, rsync, and more.
rsync, scp, and sftp are all secure since they use SSH, but rsync is preferred for syncing large or frequently updated files.
Yes, use the -a flag with rsync to copy entire folders while preserving permissions and structure.
scp is good for simple one-time copies, while rsync is more efficient for repeated transfers due to its sync and compression features.
No, FTP does not encrypt data. For secure transfers, use SFTP or SCP instead.
Try connecting using ssh username@ip_address from one machine to another. If prompted for a password and login succeeds, SSH is working.
Open TCP port 22, as it’s the default port for SSH connections.
Yes, by configuring and mounting a Samba share, one Linux system can access and exchange files with another.
UltaAI – Smart AI Assistant for Ultahost Clients
UltaAI is your advisor for anything related to domain or hosting. Experience personalised suggestions.