How to Upload a File via Ssh

Sooner or later, you'll find yourself in a situation where yous have to upload the file to the remote server over SSH or re-create a file from it.

There are various ways you can transfer files over SSH. I am going to discuss the following methods hither:

  1. scp: Legacy control which is being deprecated
  2. rsync: Popular command for file synchronization
  3. sshfs: Mounting remote directory over SSH
  4. sftp clients: GUI tool for accessing file over SFTP

For a successful file transfer over SSH, you need to

  • to have SSH access between the 2 machines
  • to know the username and password on the remote motorcar
  • IP address or hostname (on the aforementioned subnet) of the remote car

With that aside, let's run across the methods for copying files betwixt remote systems via SSH.

Method one: Use scp command to copy files over SSH

I have read that scp is going to be deprecated. All the same, information technology is my favorite tool for transferring files betwixt systems over SSH. Why? Because its syntax is similar to the cp command.

Let'south meet how to use the scp command.

Copy files from the remote machine to your local machine

Copying files from the remote Linux system over SSH

Here's the scenario. You lot want to re-create files from the remote Linux arrangement to the currently logged in system.

Here's a generic syntax that copies the file from the home directory of the user on the remote system to the current directory of your locally logged in organisation.

            scp [email protected]_address:/home/username/filename .          

Do yous see the similarity with the cp command? It'south almost the same except that y'all have to specify username and ip address with colon (:).

At present, let me bear witness y'all a real-globe case of this command.

Copy files from the remote Linux system over SSH using scp

In the example above, I copied the file remote.txt from the /home/abhishek/my_file directory on the remote system to the current directory of the local automobile.

This should give you a hint that you should know the exact location of the file on the remote system. The tab completion does non work on remote systems.

Re-create files from your local motorcar to the remote machine

Copying files to the remote Linux system over SSH

The scenario is slightly changed here. In this i, you are sending a local file to the remote system over SSH using scp.

This is a generic syntax which volition copy the filename to the dwelling house directory of username on the remote system.

            scp filename [e-mail protected]_address:/domicile/username          
Copying files to remote Linux system over SSH using scp command

In the above example, I copied local.txt file from the current directory to the habitation directory of the user abhishek on the remote arrangement.

So I logged into the remote system to show that the file has actually been copied.

You can copy directories too

Call back I told you I like scp because of its similarity with the cp control?

Like cp command, you lot tin as well use scp to copy directory over SSH. The syntax is similar to the cp command too. You lot but accept to use the -r option.

            scp -r source_dir [email protected]_address:/home/username/target_dir          

You can do a lot more with information technology. Read some more examples of scp command in this tutorial:

Using scp Command in Linux: x Practical Examples Explained

Here are some practical and essential scp command instance to show how to deeply copy files between remote Linux systems.

Method two: Use rsync to copy files and directories over SSH

Since scp is being deprecated, rsync is the adjacent best tool for copying files between remote system over SSH. Really, it is amend than scp in many terms.

The command syntax is the same as scp. Older versions of rsync had to use rsync -eastward ssh but that'southward non the case anymore.

Re-create files from the remote machine to your local machine

Permit's say y'all want to re-create a file from the home directory of the user on the remote system to the current directory of your locally logged in system.

            rsync [email protected]_address:/abode/username/filename .          

Let's take the same instance you lot saw with scp. I am copying the file remote.txt from the /home/abhishek/my_file directory on the remote system to the current directory of the local machine.

Copy files from the remote Linux system over SSH using rsync

Copy files from your local motorcar to the remote machine

Here is a generic syntax which volition copy the file to the abode directory of username on the remote system.

            rsync filename [email protected]_address:/dwelling house/username          

Time to see the existent world case. I am copying local.txt file from the current directory to the home directory of the user abhishek on the remote organisation.

Copying files to remote Linux system over SSH using rsync command

How about copying directories with rsync?

It's the aforementioned. Merely use -r option with rsync to copy entire directory over SSH between remote systems.

            rsync -r source_dir [email protected]_address:/home/username/target_dir          

Take a wait at this example. I re-create the entire my_file directory from the remote system to the local organisation.

Copy directory from the remote Linux system over SSH using rsync

rsync is a versatile tool. It is essentially a tool for 'recursively syncing' the contents between two directories and quite popular for making automated backups.

15 Practical Examples of rsync Command in Linux

Wondering how to use rsync control? This article lists some of the essential usages of the rsync command in Linux.

Method 3: Using SSHFS to access files from remote system over SSH

There is as well SSHFS (SSH Filesystem) that can exist used to admission remote files and directories. All the same, this is non very user-friendly just for copying files.

In this method, you mount the remote directory on your local arrangement. One time mounted, you can copy files between the mounted directory and the local system.

You lot may need to install sshfs on your local system commencement using your distribution's package manager.

On Debian and Ubuntu, you may use the post-obit command:

            sudo apt install sshfs          

One time you have sshfs installed on your system, y'all can use it to mountain the remote directory. It would be better to create a defended directory for the mount point.

            mkdir mount_dir          

At present mount the desired directory on the remote automobile in this fashion:

            sshfs [email protected]_address:path_to_dir mount_dir          

One time it is mounted, you tin can copy files into this directory or from this directory every bit if it is on your local automobile itself.

            cp local_file mount_dir          

Remember that you accept mounted this file. Once your work is done, you should also unmount it:

            umount mount_dir          

Here's an case where I mounted the my_file directory from the remote arrangement to the remote_dir directory on the local system. I copied the remote.txt file to the local system and then unmounted the directory.

Using sshfs to transfer files over ssh

Method 4: Use a GUI-based SFTP client for transferring files betwixt remote systems

As the last resort, you tin can use an FTP client for transferring files between remote and local systems.

FileZilla is one of the near popular cross-platform FTP customer. You can hands install on your local system.

One time installed, go to File->Site Manager and add the remote system details like IP accost, SSH port number, username and password.

Connecting to remote server using SFTP in Filezilla

Once you connect, you can see a split window view that shows the local filesystem on the left and the remote filesystem on the correct.

Using Filezilla to transfer files between remote and local Linux systems over sftp

To transfer the file, drag and drib files from left to right or right to left. A progress bar appears at the lesser.

Which method do you lot prefer?

Alright! I showed diverse command line and GUI methods that can be used for copying files over SSH.

Now information technology is upwardly to you to decide which method to apply here. Do comment your preferred method for transferring files over SSH.

peeryshim1983.blogspot.com

Source: https://linuxhandbook.com/transfer-files-ssh/

0 Response to "How to Upload a File via Ssh"

Post a Comment

Iklan Atas Artikel

Iklan Tengah Artikel 1

Iklan Tengah Artikel 2

Iklan Bawah Artikel