Copying files from one host to another using the scp utility and public key authentication

Comment 1: let’s say we need to copy a file from the host #1 to the host #2

Comment 2: suppose that the sshd service on both hosts uses Ed25519 keys


on the host #2 add the following line to the /etc/ssh/sshd_config file to enable public key authentication

PubkeyAuthentication yes

copy the content of the /etc/ssh/ssh_host_ed25519_key.pub file of the host #1 into the /root/.ssh/authorized_keys file of the host #2 to add the host #1’s public key into the host #2’s trusted keys list

ssh-ed25519 <public-key-1>

Comment: thus the connection will be established with root credentials

copy the content of the etc/ssh/ssh_host_ed25519_key.pub file of the host #2 into the /root/.ssh/known_hosts file of the host #1 and prepend it with the host #2’s DNS name and IP address in order to add the host #2 into the host #1’s trusted hosts list

host2.domain.local,192.168.200.2 ssh-ed25519 <public-key-2>

Comment: one can use the /etc/ssh/ssh_known_hosts file instead of the /root/.ssh/known_hosts file

copy a test file from the host #1 to the host #2

scp -i /etc/ssh/ssh_host_ed25519_key /root/test.txt [email protected]:/root/test.txt

Leave a Reply