0% found this document useful (0 votes)
13 views3 pages

How To Copy Files Between Machines Using SSH Access

Penggunaan SSH dan SCP pada linux
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
13 views3 pages

How To Copy Files Between Machines Using SSH Access

Penggunaan SSH dan SCP pada linux
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 3

How to Copy Files Between Machines Using SSH Access

hbayraktar.medium.com/how-to-copy-files-between-machines-using-ssh-access-60fac1eddb8e

Hakan Bayraktar November 28, 2023

Securely transferring files between a local machine and a remote server is a common need,
and the scp (secure copy) command simplifies this process by leveraging SSH (Secure
Shell) for secure file transfers.

Installing scp Command on Your Machine


Firstly, you’ll need to install the scp command on your machine. Depending on your
operating system, use one of the following commands:

For Ubuntu/Debian:

sudo apt-get install sshfs

For CentOS/RHEL:

sudo yum install fuse-sshfs

For macOS:

brew install sshfs

SCP Basic Syntax


The scp command follows a basic syntax that includes various options to manage file
transfers:

scp [options] [source_username@source_host:]source_file


[dest_userid@dest_host:]destination_dir

Commonly used options include:

Compress the file data.


Use the specified private key for the remote system.
Set a bandwidth limit for the file transfer.
Use the specified port for SSH.
Copy over the file modification and access time.
Use quiet mode. Quiet mode suppresses the progress meter and informational
messages. Error messages are still printed.
Copy directories recursively.
Print debug messages.

1/3
Examples of SCP Usage

Copying from a Remote Server to a Local Machine


To copy a file from a remote server to your local machine, use the following syntax:

scp username@remotemachineIP:/remote-path/file /local-path/

For copying multiple files using a pattern:

scp [email protected]:/root/dosya* /Users/hakan/

This pattern will copy files that match the specified pattern, such as dosya1, dosya2, and
others.

Copying a Directory from a Remote Server to a Local Machine


When dealing with directories, include the -r flag to ensure the entire directory and its
contents are copied:

scp -r [email protected]:/root/db-init /Users/hakan/

Copying from a Local Machine to a Remote Server


For copying a file from your local machine to a remote server, use the command structure:

scp /local-path/file username@remoteIP:/remote/path

example:

scp /Users/hakan/test [email protected]:/root/

Copying a Directory from a Local Machine to a Remote Server


Similarly, for directories, include the -r flag to copy the entire directory and its contents:

scp -r /local-path username@remoteIP:/remote-path

example:

scp -r /Users/hakan/Devops-lab/k10/ [email protected]:/root/

Copying Files Using RSA SSH Keys


If an RSA key is in place instead of a password for authentication, integrate the -i flag to
specify the identity key:

scp -i /path/to/key [email protected]:/remote/path/to/file /local/path

2/3
example:

scp -i /Users/hakan/ssh/hakan.pem -r /Users/hakan/Devops-lab/hello-test/


[email protected]:/root/

By following these scp commands, you can efficiently and securely transfer files and
directories between local and remote locations, offering convenience and flexibility in
managing your data across systems.

3/3

You might also like