GitHub Action 脚本问题

我想用 GitHub Action 远程登录服务器更新网站,但没法成功,SSH 命令不能识别我的私钥。有没有大佬能帮忙看一下。 :joy:

我用的命令是:

echo "$SSH_PRIVATE_KEY" > id_rsa 
chmod 600 id_rsa
ssh-keygen -y -f id_rsa | tail -c 48 # 用私钥生成公钥,截取最后一段。
ssh "suse-zh@$SSH_SERVER_ADDRESS" -p38324 -v -i id_rsa < utils/git-pull.sh

输出是

fTRrtWKZwiWfm5qyN7pddPc= suse-zh@github-actions
^ 用私钥生成公钥,截取最后一段。这里就可以看出我的私钥没问题
OpenSSH_8.2p1 Ubuntu-4ubuntu0.2, OpenSSL 1.1.1f  31 Mar 2020
debug1: Reading configuration data /etc/ssh/ssh_config
debug1: /etc/ssh/ssh_config line 19: include /etc/ssh/ssh_config.d/*.conf matched no files
debug1: /etc/ssh/ssh_config line 21: Applying options for *
Pseudo-terminal will not be allocated because stdin is not a terminal.
debug1: Connecting to *** [***] port 38324.
debug1: Connection established.
debug1: SELinux support disabled
debug1: identity file id_rsa type -1
^ 没有识别,类型为-1 就是不存在
debug1: identity file id_rsa-cert type -1

请把 SSH 的选项放在目标机器前边。请记得 chmod 600 你的私钥。

刚刚尝试了一下,选项顺序与权限应该不是出现问题的原因。 :fearful:

不重定向脚本,直接执行个命令试试呢?

算了,隔壁 @hokuto 准备用现成的 RSync Action 来同步,此帖终结 :rofl: