使用 rsync 与 GCP 的权限被拒绝公钥

使用 rsync 与 GCP 的权限被拒绝公钥

我正在尝试使用 rsync 连接到 GCP 虚拟机。每次我这样做时,都会收到与权限相关的奇怪错误。

我检查了我的用户名是否属于 sudoers 组,因此我看不出问题出在哪里。我登录到我的 GCP 实例,该实例按照我的 Mac OS 用户名格式在 /home 下创建了一个用户目录,

以下是我一直尝试的命令以及结果...

C02YT3UDLVDL:proj-name j.lname$ ssh -i ~/.ssh/google_compute_engine    
[email protected] The authenticity of host 'xx.xxx.xxx.xx (xx.xxx.xxx.xx)' 
can't be established. ECDSA key fingerprint is 
SHA256:JW7VfidHTsAtq8JjF9bEkdfIjdskIAadfs80.Are you sure you want to continue  
connecting (yes/no)? yes Warning: Permanently added 'xx.xxx.xxx.xx' (ECDSA) to 
the list of known hosts.

之后我尝试移动测试目录......

rsync -Pavz testDir/* xx.xxx.xxx.xx:/home/j.lname

并得到

ssh_exchange_identification: Connection closed by remote host
rsync: connection unexpectedly closed (0 bytes received so far) [sender]
rsync error: unexplained error (code 255) at io.c(226) [sender=3.1.2]

再试一次得到:

 $ rsync -Pavz testDir/* xx.xxx.xxx.xx:/home/j.lname/
 The authenticity of host 'xx.xxx.xxx.xx (xx.xxx.xxx.xx)' can't be established.
 ECDSA key fingerprint is SHA256:Q8kqWi3iyLno3Q8kqWi3iyLno3Q8kqWi3iyLno3.
 ECDSA key fingerprint is MD5:ff:56:c3:21:cc:f1:a7:62:1b:72:bc:54:8e:f7:c8:1a.
 Are you sure you want to continue connecting (yes/no)? yes
 Warning: Permanently added 'xx.xx.xx.xx' (ECDSA) to the list of known hosts.
 yPermission denied (publickey).

編輯:

根据这里某人的建议,也尝试过

rsync -Pavz -e "ssh -i ~/.ssh/google_compute_engine" testDir/* 
[email protected]:/home/j.lname/

那时得到了:

bash: rsync: command not found
rsync: connection unexpectedly closed (0 bytes received so far)   
[sender]
rsync error: error in rsync protocol data stream (code 12) at 
io.c(226) [sender=3.1.3]

答案1

使用 rsync 时,您必须像使用 ssh 一样指定 ssh 密钥。这就是您被拒绝权限的原因。我们可以使用 -e 选项来做到这一点:

rsync -Pavz -e "ssh -i ~/.ssh/google_compute_engine" testDir/* [email protected]:/home/j.lname 

编辑:

目标服务器上也应安装 Rsync 命令

答案2

需要补充的是,确保遇到此问题的任何人都能理解......您需要在源机器和目标机器上执行 ssh key-gen 过程。

这意味着确保源的 id_rsa.pub 的内容保存在目标~/.ssh/authorized_keys文件夹中...并且...反之亦然(目标的 id_rsa.pub 保存到源中的相同位置)

对需要在公钥、私钥和authorized_keys文件夹上设置的chmod权限进行一些其他搜索,因为这显然也很重要。

相关内容