Translate into your own language

Wednesday, September 29, 2021

Step by Step - How To Setup Password less SSH between nodes

We have to setup the password less ssh between primary and standby nodes for postgres user

a)      On Standby Server(192.168.204.134) -

 [postgres@Replica1 .ssh]$ ssh-keygen -t rsa

Generating public/private rsa key pair.

Enter file in which to save the key (/home/postgres/.ssh/id_rsa):

Enter passphrase (empty for no passphrase):

Enter same passphrase again:

Your identification has been saved in /home/postgres/.ssh/id_rsa.

Your public key has been saved in /home/postgres/.ssh/id_rsa.pub.

The key fingerprint is:

SHA256:hxSzxo6ESc+kzBNtQ4FGMnlC/N4Duax9XflSnWKwcAQ postgres@Replica1

The key's randomart image is:

+---[RSA 3072]----+

| o+o+++.E.       |

|  +*+O+. +.      |

|   =Bo+.=.       |

|    +o =..o      |

|   o +. So.+ . . |

|    + o  .+ + o  |

|   o   o . + .   |

|  . . . . . .    |

|     .     .     |

+----[SHA256]-----+

[postgres@Replica1 .ssh]$ ls -ltr

total 12

-rw-r--r--. 1 postgres postgres  531 Sep 29 06:57 known_hosts

-rw-r--r--. 1 postgres postgres  571 Sep 29 07:26 id_rsa.pub

-rw-------. 1 postgres postgres 2602 Sep 29 07:26 id_rsa

 Make a file authorized_keys under /home/postgres/.ssh directory and then copy the content of id_rsa.pub

[postgres@Replica1 .ssh]$ cat id_rsa.pub >> authorized_keys

 

b)      On Primary Server(192.168.204.133) –

[postgres@Master .ssh]$ ssh-keygen -t rsa

Generating public/private rsa key pair.

Enter file in which to save the key (/home/postgres/.ssh/id_rsa):

Enter passphrase (empty for no passphrase):

Enter same passphrase again:

Your identification has been saved in /home/postgres/.ssh/id_rsa.

Your public key has been saved in /home/postgres/.ssh/id_rsa.pub.

The key fingerprint is:

SHA256:wsvoDy4VhNi1r3KisHrivuhzePdEHTw31y8R5NUsmyk postgres@Master

The key's randomart image is:

+---[RSA 3072]----+

| o o.        .o.o|

|. o ..  .    .ooo|

|   ..    + o .o* |

|    .o  . + E +..|

|     .+.S.   .. .|

|    .+.o       . |

|. +.= o.         |

|+=oO o.          |

|XB=.+.o.         |

+----[SHA256]-----+

[postgres@Master .ssh]$ ls -trl

total 12

-rw-r--r--. 1 postgres postgres  531 Sep 18 15:34 known_hosts

-rw-r--r--. 1 postgres postgres  569 Sep 29 07:24 id_rsa.pub

-rw-------. 1 postgres postgres 2602 Sep 29 07:24 id_rsa

 

Make a file authorized_keys under /home/postgres/.ssh directory and then copy the content of id_rsa.pub

 

[postgres@Master .ssh]$ cat id_rsa.pub >> authorized_keys

 

c)       Append the content of authorized_keys  file from replica server to authorized_keys of master server and vice-versa.

[postgres@Replica1 ~]$ cat .ssh/id_rsa.pub | ssh postgres@192.168.204.133 'cat >> .ssh/authorized_keys'

[postgres@Master ~]$ cat .ssh/id_rsa.pub | ssh postgres@192.168.204.134 'cat >> .ssh/authorized_keys'


d)Change the permission of .ssh and and authorized_keys like below on both side –

On Primary -

[postgres@Master ~]$ chmod 700 .ssh

[postgres@Master .ssh]$ chmod 640 authorized_key

On Standby –

[postgres@Replica1~]$ chmod 700 .ssh

[postgres@ Replica1 .ssh]$ chmod 640 authorized_key

e)     Check the password less SSH from both nodes. It should work like below –




No comments:

Post a Comment