rsync exited with code 255.Load key “...“: invalid format Permission denied, please try again.
在配置自动部署前端项目到服务器上时,登录服务器使用的是秘钥登录。在开头把问题关键说一下:秘钥格式不对!
·
在配置github actions
自动部署前端项目到服务器上时,登录服务器使用的是秘钥登录。
出现报错:
[general] GITHUB_WORKSPACE: /home/runner/work/clogin-frontend/clogin-frontend
[SSH] Creating /home/runner/.ssh dir in /home/runner/work/clogin-frontend/clogin-frontend
✅ [SSH] dir created.
[SSH] Creating /home/runner/.ssh/known_hosts file in /home/runner/work/clogin-frontend/clogin-frontend
✅ [SSH] file created.
✅ Ssh key added to `.ssh` dir /home/runner/.ssh/deploy_key
[Rsync] Starting Rsync Action: /home/runner/work/clogin-frontend/clogin-frontend/public/ to ***@***:/study/github_actions/
[Rsync] exluding folders
⚠️ [Rsync] error: rsync exited with code 255
⚠️ [Rsync] stderr: Warning: Permanently added '***' (ECDSA) to the list of known hosts.
Load key "/home/runner/.ssh/deploy_key": invalid format
Permission denied, please try again.
Permission denied, please try again.
***@***: Permission denied (publickey,gssapi-keyex,gssapi-with-mic,password).
rsync: connection unexpectedly closed (0 bytes received so far) [sender]
rsync error: unexplained error (code 255) at io.c(235) [sender=3.1.3]
⚠️ [Rsync] stdout:
⚠️ [Rsync] cmd: rsync /home/runner/work/clogin-frontend/clogin-frontend/public/ ***@***:/study/github_actions/ --rsh "ssh -p 22 -i /home/runner/.ssh/deploy_key -o StrictHostKeyChecking=no" --recursive --exclude= -rltgoDzvO
1: 0xb02ec0 node::Abort() [/home/runner/runners/2.299.1/externals/node16/bin/node]
2: 0xb76589 [/home/runner/runners/2.299.1/externals/node16/bin/node]
3: 0xd4a18e [/home/runner/runners/2.299.1/externals/node16/bin/node]
4: 0xd4b5af v8::internal::Builtin_HandleApiCall(int, unsigned long*, v8::internal::Isolate*) [/home/runner/runners/2.299.1/externals/node16/bin/node]
5: 0x15e7959 [/home/runner/runners/2.299.1/externals/node16/bin/node]
在开头把问题关键说一下:秘钥格式不对!
关于怎么配置服务器秘钥登录,可以看看这个:
1. 制作密钥对
首先在服务器上制作密钥对。首先用密码登录到你打算使用密钥登录的账户,然后执行以下命令:
[root@host ~]$ ssh-keygen <== 建立密钥对
Generating public/private rsa key pair.
Enter file in which to save the key (/root/.ssh/id_rsa): <== 按 Enter
Created directory '/root/.ssh'.
Enter passphrase (empty for no passphrase): <== 输入密钥锁码,或直接按 Enter 留空
Enter same passphrase again: <== 再输入一遍密钥锁码
Your identification has been saved in /root/.ssh/id_rsa. <== 私钥
Your public key has been saved in /root/.ssh/id_rsa.pub. <== 公钥
The key fingerprint is:
0f:d3:e7:1a:1c:bd:5c:03:f1:19:f1:22:df:9b:cc:08 root@host
密钥锁码在使用私钥时必须输入,这样就可以保护私钥不被盗用。当然,也可以留空,实现无密码登录。
现在,在 root 用户的家目录中生成了一个 .ssh 的隐藏目录,内含两个密钥文件。id_rsa 为私钥,id_rsa.pub 为公钥。
2. 在服务器上安装公钥
键入以下命令,在服务器上安装公钥:
[root@host ~]$ cd .ssh
[root@host .ssh]$ cat id_rsa.pub >> authorized_keys
如此便完成了公钥的安装。为了确保连接成功,请保证以下文件权限正确:
[root@host .ssh]$ chmod 600 authorized_keys
[root@host .ssh]$ chmod 700 ~/.ssh
3. 设置 SSH,打开密钥登录功能
编辑 /etc/ssh/sshd_config 文件,进行如下设置:
RSAAuthentication yes
PubkeyAuthentication yes
另外,请留意 root 用户能否通过 SSH 登录:
PermitRootLogin yes
最后,重启 SSH 服务:
[root@host .ssh]$ service sshd restart
但是,到这里有一个很重要的步骤:将私钥转换成pem
格式:
ssh-keygen -p -f ~/.ssh/id_rsa -m pem
vim 打开id_rsa
,看看开头是不是-----BEGIN RSA PRIVATE KEY-----
配置秘钥登录
将服务器上的id_rsa
文件传到本机,打开文件,复制全选,再到 github 代码库的setting
里面,配置secret
下的actions
,将刚刚复制的秘钥配置到secret
中,让github帮我们保管。之后在actions配置文件中通过${{ secrets.自定义名称 }}
来引入就可以。
总之是秘钥格式问题,需要转换一下。
更多推荐
已为社区贡献1条内容
所有评论(0)