How to copy files remotely via SSH without entering a password

s2 0

SSH (Secure Shell) is an encrypted protocol used to connect to the remote device. By default, it works on TCP port 22. There are two methods of connecting to the remote server using SSH, one using password authentication and another using public key authentication. In this tutorial you will learn how to generate an SSH key in CentOS8 and copy files via SSH (SCP) without entering a password.

Generate SSH key

Before generating the SSH key. First of all, check if SSH is installed or not. To check, open the Terminal and enter the following command.

# ssh –V

After checking the SSH package. Now I am going to generate the SSH key with the following command.

# ssh-keygen

For added security, you can specify the encryption algorithm as needed as shown below.

# ssh-keygen –t rsa

# ssh-keygen –t rsa –b 4096

After entering the above command, the following output should appear.

rsa key filename

To save the file in a suggested directory, press Enter.

Next, you will be prompted to enter the passphrase, leave it blank and press Enter. The following output should appear.

Key pair was created

The SSH key was generated successfully. You can verify this by using the following command to view your SSH key.

Show pubkeyadvertising

This command prints out your SSH key.

Copy the SSH to the remote side, use the following command.

# ssh-copy-id –i [email protected]

Copy key to target server

Repeat all of the above processes on the remote side if you want two-way communication.

Copy file without password:

To copy the file on the remote side with the following command.

# scp file.txt [email protected]:/tmp/

Copy file with scp

It will copy your text file to the remote server, go to the remote page to check and see if your file has been copied.

The file was copied to the remote server

SSH configuration

Sometimes you need to configure SSH on the remote side for authentication. In this case, activate the SSH authentication key, open the / etc / ssh / sshd_config and activate or add the following lines.

RSAAuthentication yes

PubkeyAuthentication yes

Save the configuration file and restart the service with the following command.

# systemctl restart sshd

diploma

In this tutorial we learned how to generate the SSH authentication key in CentOS8 and copy the file over the SSH without entering the password. I hope this tutorial will help you understand SSH key generation and how to copy the file on the far end.

How to copy files remotely via SSH without entering a password