我正在尝试通过构建脚本来自动化与Git的交互。
我想
使用.pem文件连接亚马逊实例
从该ubuntu实例运行git命令
我是shell编程的初学者。我可以尝试像
那样做#!/bin/bash
GIT_REPO='git_repo'
BRANCH='branch'
ssh -i ~/Downloads/4EBDBInstance.pem ubuntu@122.248.237.95
cd $GIT_REPO
git fetch -a
git checkout $BRANCH
git rebase origin/$BRANCH
我收到了错误
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
@ WARNING: UNPROTECTED PRIVATE KEY FILE! @
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
Permissions 0644 for '/PATH/Instance_key.pem' are too open.
It is required that your private key files are NOT accessible by others.
This private key will be ignored.
bad permissions: ignore key: PATH/Instance_key.pem
Permission denied (publickey).
实际上我试图在bash文件中实现以下Unix命令
$sudo ssh -i PATH/instance_key.pem ubuntu@000.000.000.00
$cd git_repo
$git fetch -a
$git checkout master
$git rebase origin/master
(note:- need to inform with a message if any conflicts occurs and continue)
$sudo ssh -i PATH/instance_key.pem ubuntu@111.111.111.11
$cd git_repo
$git fetch -a
$git checkout release
$git rebase origin/release
(note:- need to inform with a message if any conflicts occurs)
实施它的任何帮助
答案 0 :(得分:2)
ssh将读取其stdin以运行命令。你可以使用heredoc:
ssh -i ~/Downloads/4EBDBInstance.pem ubuntu@122.248.237.95 <<END
cd $GIT_REPO
git fetch -a
git checkout $BRANCH
git rebase origin/$BRANCH
END
答案 1 :(得分:2)
授予您的亚马逊密钥400权限,然后尝试
GIT_REPO='git_repo'
BRANCH='branch'
ssh -i ~/Downloads/4EBDBInstance.pem ubuntu@122.248.237.95 "cd $GIT_REPO && git stash && git checkout $BRANCH && git fetch -a && git rebase origin/$BRANCH"
它将连接实例并从那里运行那些命令。