Categories: LinuxShell

How to remotely copy files over SSH without entering a password

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

Generate SSH Key

Before generating the SSH Key. Firstly, verify the SSH is installed or not. To verify, open up the terminal and type the following command.

# ssh –V

After verifying the SSH package. Now I am going to generate the SSH key, using the following command.

# ssh-keygen

To tighten up the security, you can mention the encryption algorithm according to your need, as shown below.

# ssh-keygen –t rsa

# ssh-keygen –t rsa –b 4096

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

To save the file in a suggested directory press enter.

Next, it will prompt you to enter the passphrase, leave it empty, and press enter. The following output should appear.

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

This command will print your SSH key.

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

# ssh-copy-id –i root@test.com

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 using the following command.

# scp file.txt root@test.com:/tmp/

It will copy your text file to the remote server, for verification go to the remote side and verify that your file has been copied.

SSH Configuration

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

RSAAuthentication yes

PubkeyAuthentication yes

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

# systemctl restart sshd

Conclusion

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 to understand SSH key generation and copy the file at the remote end.

Karim Buzdar

About the Author: Karim Buzdar holds a degree in telecommunication engineering and holds several sysadmin certifications. As an IT engineer and technical author, he writes for various web sites. You can reach Karim on LinkedIn

Recent Posts

How to Install Magento 2 on AlmaLinux

Magento is a free and open-source e-commerce platform written in PHP. It is simple, easy…

1 year ago

How to Install ISPConfig Hosting Control Panel with Apache Web Server on Ubuntu 24.04

ISPConfig is an open-source control panel that allows users to manage multiple servers from a…

1 year ago

How to Test your Email Server (SMTP) Using the Telnet Command

As a Linux administrator, you may find it necessary to troubleshoot or test your Simple…

1 year ago

Managing Network Interfaces and Settings on Ubuntu 24.04 with nmcli

Ubuntu 24.04, like many modern Linux distributions, relies on the NetworkManager for managing network connections.…

2 years ago

Using Restic Backup on Ubuntu 24.04

Restic is a modern, open-source backup program designed for efficiency, security, and simplicity. It enables…

2 years ago

Installing phpMyAdmin on Rocky Linux 9 and Securing it with Let’s Encrypt SSL

phpMyAdmin is a popular free tool written in PHP intended to administer MySQL and MariaDB…

2 years ago