copy file from local to server ssh code example

Example 1: scp send file

scp ./file.txt remote_username@remote_ip:/remote/directory

Example 2: centos copy files ssh

scp <source> <destination>

#To copy a file from B to A while logged into B:
scp /path/to/file username@a:/path/to/destination

#To copy a file from B to A while logged into A:
scp username@b:/path/to/file /path/to/destination

Example 3: ssh transfer file from local to remote

scp file.txt [email protected]:/remote/directory

Example 4: scp local to remote

scp -i <private_key> ./file.txt remote_username@remote_ip:/remote/directory

Example 5: copy file from ssh server to local

scp host_name:file_server path_local

Example 6: how to copy file using ssh

# This need to be done in server side only
$ sudo apt install openssh-server
$ sudo systemctl enable ssh
$ sudo systemctl start ssh
# Need to be done in client side only
$ scp myfile.txt remote_user@remote_ip_address