How to configure passwordless ssh and scp



Create pair of private key and public key

Open the terminal and then use ssh-keygen to generate the pair of keys

By default system will generate the keys with name id_rsa & id_rsa.pub. If you want to generate with custom name then enter the file name when it prompts.

passphrase will act as password for your key to avoid misuse, you can keep it blank also.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
$ ssh-keygen -t rsa**

Generating public/private rsa key pair.
Enter file in which to save the key (/home/author/.ssh/id_rsa):
Enter passphrase (empty for no passphrase):
Enter same passphrase again:
Your identification has been saved in /home/author/.ssh/id_rsa.
Your public key has been saved in /home/ec2-user/.ssh/id_rsa.pub.
The key fingerprint is:
SHA256:7B2G20AHF7PFHIACElEAzEO+i293wReZI49T7MMH1ns author@tutorialflix
The key's randomart image is:
+---[RSA 2048]----+
|=o==o. ..==o. |
|.+ . . .o +o |
| .. o.+o |
| . .oXo. |
| . . OS+o. |
|. . =.**o.E |
|.. +ooo. |
| .. . . |
| ... . |
+----[SHA256]-----+

Upload Your Public Key to Remote Linux Server

You can upload the key using ssh-copy-id command, which is shipped by the openssh-client package.

1
2
3
4
5
6
7
8
9
ssh-copy-id remote-user@server-ip
**enter password**

/usr/bin/ssh-copy-id: INFO: attempting to log in with the new key(s), to filter out any that are already installed
/usr/bin/ssh-copy-id: INFO: 1 key(s) remain to be installed -- if you are prompted now it is to install the new keys
remote-user@server-ip's password:
Number of key(s) added: 1
Now try logging into the machine, with: "ssh 'remote-user@server-ip'"
and check to make sure that only the key(s) you wanted were added.

The public key is stored in .ssh/authorized_keys file under the remote user’s home directory. Now ssh into the remote server and you will be able to login without password

Your browser is out-of-date!

Update your browser to view this website correctly. Update my browser now

×