Using scp to transfer files between computers.

dos2unix

Well-Known Member
Joined
May 3, 2019
Messages
3,498
Reaction score
3,234
Credits
31,331

Using scp (Secure Copy) in Linux​

scp (Secure Copy) is a command-line utility that allows you to securely transfer files between hosts on a network. It uses SSH (Secure Shell) to provide encryption and authentication, ensuring that your data is protected during transfer. Unlike sftp, scp does not require a separate server and is typically included as part of the SSH suite.

Basic Commands​

Uploading a File: To upload a file from your local machine to a remote server:
Code:
 scp /path/to/local/file username@remote_host:/path/to/remote/directory

Downloading a File: To download a file from a remote server to your local machine:
Code:
 scp username@remote_host:/path/to/remote/file /path/to/local/directory

Using Wildcards​

Downloading Files with the Same Beginning Characters: To download all files that start with "example" from a remote directory:
Code:
 scp username@remote_host:/path/to/remote/directory/example* /path/to/local/directory

Downloading Files with the Same Ending Characters: To download all files that end with ".txt" from a remote directory:
Code:
 scp username@remote_host:/path/to/remote/directory/*.txt /path/to/local/directory

Recursive File Transfer​

Downloading Files Recursively: To download an entire directory and its contents from a remote server:
Code:
 scp -r username@remote_host:/path/to/remote/directory /path/to/local/directory

Integration with SSH​

scp is part of the SSH suite, which means it leverages SSH for secure data transfer. This integration ensures that scp does not require a separate server like sftp does. Instead, it uses the SSH protocol to authenticate and encrypt the data being transferred.

Advantages and Disadvantages of scp vs sftp​

Advantages of scp:

  • Direct File Transfer: scp allows you to transfer files directly to and from any directory you have permissions for, without needing to navigate through a file system.
  • Simplicity: The command syntax is straightforward and easy to use for quick file transfers.
Disadvantages of scp:

  • No Directory Browsing: Unlike sftp, scp does not allow you to log in and browse directories interactively.
  • Limited Functionality: scp is primarily designed for file transfer and does not offer advanced features like file manipulation or directory listing.
Advantages of sftp:

  • Interactive Mode: sftp allows you to log in to a remote server and browse directories, making it easier to navigate and manage files.
  • Advanced Features: sftp provides additional commands for file manipulation, such as renaming, deleting, and creating directories.
Disadvantages of sftp:

  • Separate Server Requirement: sftp requires an sftp server to be running on the remote host, which adds an extra layer of setup and maintenance.
  • Restricted Directory Access: You can only download from directories that the sftp server is configured to use, limiting access compared to scp.
By understanding the strengths and limitations of both scp and sftp, you can choose the right tool for your specific file transfer needs.
 


SCP (and SSH) is super nice to use ... IF it is setup correctly already. Setting it up is not the easiest thing (but mileage may differ). A typical effect of these tools is that you can set them up by either asking the password on every usage, or just have them working without passwords altogether. But, you guessed it, setting it up with the password not being asked, is additional setup.

So, it's a great tool, but beware of the setup. I'm always looking for tools that are indicative of their usage, and incorrect usage as well, but the problem is that when it comes to " safety " functionality, the tools become less reactive, and that is on purpose. It's good, but often I see on screen that either the command just doesn't work, or that it asks for a password, and they YOU can try to find why that is, the tool is NOT going to give even the slightest clue.
 
Out of the box ? Well, I never experienced that ...

So, you create a user on server 1, and then I can go to server 2, and SSH to that new user on server 1

That will be a first.

It would also be a huge security problem by the way


My experience = setting up SSH/SCP is a PITA
 
You see, I think that is where there is a bit of a difference, I'm a Linux server admin and software administrator. All SSH by default is 100% disabled when the OS is installed, and then, based on need, we setup the SSH to and from and as which user is needed.

So, the Linux machines I work on are all servers. How can the connection be setup if the user isn't created yet ?

How do you setup SSH to a user that doesn't exist on a server that you have zero control over ?

SSH is about setting up connection between machines, and AFAIK, all of this on ROOT level.

If on Linux clients that is different, well, that is possible. But I'm talking about actual secure machines. They're not even available from the internet, yet they are better protected than many machines that are available on the net. Why ? Well maybe because the owner pays billions for it. That may be reason.
 
All SSH by default is 100% disabled when the OS is installed, and then, based on need, we setup the SSH to and from and as which user is needed.

Not on any distro I use. It's enabled by default for all users on Redhat, Fedora, CentOS, Alma, Rocky, Ubuntu, and SuSE.

How can the connection be setup if the user isn't created yet ?

which is why I said...

If I have an account of both servers yes.
 

What you mean is : it's installed as a package, I mean "setup ready to be used", configured and all

Not on any distro I use. It's enabled by default for all users on Redhat, Fedora, CentOS, Alma, Rocky, Ubuntu, and SuSE.
 


Members online


Latest posts

Top