Skip to content

SSH Connect Trust Configuration

1. Config trust

  • 1.1 Create private key and public key

Create ssh key (private key and public key)

cd ~  ## Enter the user's home directory
ssh-keygen -t rsa

image-20260202134108337

Generate the authorization key through the public key

cat /home/postgres/.ssh/id_rsa.pub > /home/postgres/.ssh/authorized_keys

image-20260202134448313

  • 1.2 Check ssk folder and key file authority

.ssh目录的权限为700,其下面的authorized_keys和私钥权限为600

否则会因权限问题导致无法免密登陆

ls -al
chmod 600 .ssh/authorized_keys .ssh/id_rsa
ll .ssh/

image-20260202135143355

  • 1.3 Copy .ssh folder to other server
scp -rp .ssh postgres@xx.xx.xx.xx:/home/postgres/

如果需要2台主机互相免密访问,请将 .ssh/authorized_keys 内容互相添加到各自主机中

  • 1.4 Test access to trusted host
ssh 10.41.21.132 hostname; ls -l /home/postgres/.ssh/