2

我试图让这个命令作为用户 postgres 工作(所以我可以发送 wal 文件):

rsync -a /tmp/test postgres@server2:/tmp/test

但我得到了错误:

Permission denied (publickey).

我已经在 server1ssh-keygen eval `ssh-agent`ssh-add以 postgres 用户身份运行。keygen 创建了/var/lib/postgresql/.ssh/id_rsaid_rsa.pub我可以看到它是使用ssh -vvv postgres@server2.

在 server2 上,我创建了/var/lib/postgresql/.ssh/authorized_keys将 id_rsa.pub 表单 server1 的内容放入其中。它归 postgres 用户和组以及 chmod 600 所有。该.ssh目录也归 postgres 和 chmod 700 所有。

我可以从 server2 上的详细 sshd 日志中看到Failed publickey for postgres...

我错过了什么?我猜 sshd 没有在 server2 上查看我的 authorized_keys 文件

4

1 回答 1

-2

假设您的从服务器允许密钥身份验证,您只需/etc/ssh/sshd_config在设置“AllowedUsers”时进行更新,在这种情况下,您需要确保postgres在该列表中。

除此之外,只需ssh-keygen(将私钥密码留空),然后将~/.ssh/authorized_keys目录/文件添加到从服务器。的主目录postgres/var/lib/postgresql,但是如果您su以用户身份执行这些操作postgres,则可以使用~,更不用说您不需要chown任何东西,因为postgres将拥有主服务器上生成的 ssh 密钥,并且postgres将拥有从服务器上创建的目录/文件。

请务必在主服务器和从服务器上安全地设置文件权限:

在主人

chmod 700 ~/.ssh

chmod 600 ~/.ssh/id_rsa

chmod 600 ~/.ssh/id_rsa.pub

chmod 600 ~/.ssh/known_hosts  # this one won't exist until you SSH once

在奴隶

chmod 700 ~/.ssh

chmod 600 ~/.ssh/authorized_keys
于 2016-07-28T05:17:33.503 回答