返回博客

Github Actions 远程 SSH 和 SCP 操作

本文记录了使用 Github Actions 进行远程 SSH 和 SCP 操作的方法,包括使用 appleboy/scp-action 和 appleboy/ssh-action 两个仓库,以及使用命令行 SCP 和 SSH 命令的替代方案,并提供了一些调试方法的链接。

Mt.r
|

记一下 Github Action Remote SSH SCP

仓库

替代方案

SCP 命令行

mkdir -p ~/.ssh
echo "${{ secrets.SSH_KEY }}" > ~/.ssh/id_rsa
chmod 700 ~/.ssh/id_rsa
ssh-keyscan -H 119.28.92.99 >> ~/.ssh/known_hosts
scp -o StrictHostKeyChecking=no -r ./public.zip root@119.28.92.99:/root/test/public.zip

SSH 命令行

单个命令

ssh user1@server1 command1
ssh user1@server1 'command2'
# pipe #
ssh user1@server1 'command1 | command2'
# multiple commands (must enclose in quotes #
ssh admin@box1 "command1; command2; command3"

多个命令

ssh server_name < commands.txt
ssh user@server_name < commands.txt
ssh admin@ls.backup < commands.txt

其他

调试