This topic explains how to make the scp utility not ask for a password when copying files using a specific username on the target machine. Useful for automation - when you need to run scheduled actions that involve connecting to a remote machine and copying information from it (or to it) using a specific remote username.
So, first of all let's configure the ssh client on the current machine. Carefully check its settings so that it allows connecting to the remote machine without entering additional parameters (for example, if you use a port other than 22).
It is located at: /etc/ssh/ssh_config
Don't confuse it with sshd_config - these are different files
After that we perform the following steps (all of them are performed on the machine from which access to the remote computer will be carried out): as the user under which we will be using scp, we run:
# ssh-keygen
# ssh-copy-id -i /home/[username]/.ssh/id_rsa.pub [remote_user]@[remote_ip]
When ssh-keygen asks for a password, just press Enter - i.e. an empty password.
When asked "where to put the file", answer: /home/[username]/.ssh/id_rsa.pub
Here:
- [username] - is the local username on the machine from which you will be connecting and under which you will be running SCP.
- [remote_user] - is the username on the remote machine under which you will be connecting via SSH.
- [remote_ip] - is the IP address of the remote machine
That's it, now all that's left is to check SCP. If the ssh-copy-id command completed successfully - everything will work.
PS. For FreeBSD.The ssh-copy-id utility does not ship out of the box on FreeBSD. To install it, run:
$ cd /usr/ports/security/ssh-copy-id
$ sudo make install clean
Comments