AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |
Back to Blog
Ssh copy files to remote8/3/2023 ![]() ![]() Now from ComputerB, you can issue the scp command in the following manner to copy files from ComputerB -> ComputerA where ComputerAUser is your username on ComputerA: scp -P 2222 /path/to/file/on/ComputerB happening here? It looks like we are simply telling ComputerB to send the file back to itself because we're passing localhost instead of ComputerA. We'll use this port to reverse-tunnel back to ComputerA from ComputerB. ssh -R 2222:localhost:22 where ComputerBUser is the username for the account on ComputerB being authenticated and 2222 is a free port on ComputerB. When establishing the ssh connection ComputerA -> ComputerB, do so with the -R option in the following manner. In this case, you can configure your ssh tunnel from ComputerA -> ComputerB such it can tunnel reverse connections as well. However, you may not always have access to make these kinds of changes. In this scenario, you would typically need to configure port-forwarding in the NAT firewall. To use this solution, run from ComputerB: scp /path/to/file/on/ComputerB 2: If ComputerA is behind an NAT firewall It requires you to have an ssh server (and client) installed on both ends (computerA and computerB). This is a swift and easy solution, combining scp and ssh (scp performs a secure copy using ssh protocols). Scenario 1: If ComputerA is not behind an NAT firewall ComputerB is a remote machine that you can access via ssh. Say you have two computers, ComputerA and ComputerB. I'm posting a separate solution altogether to account for the situation where it may be difficult because of network structure (think NAT firewall) to simply ssh back into the local system. If you want to authenticate the remote host connection using a keypair file, specify the path of the file using the -i flag.Nullmeta's answer is completely valid, and perhaps nullmeta will edit to provide the clarification you're looking for. scp -q /home/document.txt Use a Keypair File for Authentication However, you can choose not to view this information using the -q flag. When you enter the scp command in order to transfer files, the terminal displays the progress bar and other related information on the screen. If you want to copy directories instead of files, use the -r flag to transfer directories recursively. ![]() scp -p /home/document.txt Copy Directories Notice that -P and -p flags are different from each other. If for any reason you want to preserve these timestamps, use the -p flag. When you transfer the file to another location using scp, the timestamps of the destination file are overridden by the current time. You might know that Linux sets timestamps for each file to store the modification time, access time, and change time associated with the file. To use some other port number while copying files from a local host to a remote host: scp -P 35 /home/document.txt aforementioned command will ensure that the scp command uses port 35 for transferring files. ![]() Also, the user should have write access to the directory in which you want to save the file.Īfter issuing the above-mentioned command, the system will ask you for the remote user's password. Keep in mind that the user must exist on the remote server if you want to transfer the files successfully. The destination path is separated from the remote host details using the colon character ( :). In the above command, user is the username and remote-host is the domain name. You have to specify the username and domain name of the remote server as well. And the destination is the path of the file on the remote host. To upload a file named document.txt to a remote host: scp /home/document.txt that the source is the path of the file on your local storage. If you are a server administrator, then transferring files between a local host and remote hosts might be useful to you. The basic syntax of the scp command is: scp Transfer From Local Host to a Remote System ![]()
0 Comments
Read More
Leave a Reply. |