GIT 克隆 SSH 在本地工作,但不通过远程脚本。

3

我遇到了一些奇怪的.git问题。

⚡️ mhn-app curl -s 45.55.88.57/code/reCloneMHNApp.sh | sudo bash

我一直得到以下信息:

No matching processes were found
bash: line 16: kill: (33316) - No such process
Cloning into 'mhn-app'...
git@hq-bitbucket.tiny.com: Permission denied (publickey).
fatal: Could not read from remote repository.

Please make sure you have the correct access rights
and the repository exists.

拒绝访问(公钥)。

如果我手动运行这些命令,我可以正常克隆。

git clone ssh://git@hq-bitbucket.tiny.com:7999/app/mhn-app.git
cd mhn-app/
git status
git checkout .
git checkout swagger-api
pod install
open .

我收到了✅

Cloning into 'mhn-app'...
remote: Counting objects: 10079, done.                                                                                                                  
remote: Compressing objects: 100% (5058/5058), done.                                                                                                    
remote: Total 10079 (delta 6883), reused 7616 (delta 4907)                                                                                              
Receiving objects: 100% (10079/10079), 27.06 MiB | 11.07 MiB/s, done.
Resolving deltas: 100% (6883/6883), done.
⚡️  Apps  cd mhn-app/
⚡️  mhn-app  git status
On branch master
Your branch is up to date with 'origin/master'.

nothing to commit, working tree clean
⚡️  mhn-app  git checkout .
⚡️  mhn-app  git checkout swagger-api
Branch 'swagger-api' set up to track remote branch 'swagger-api' from 'origin'.
Switched to a new branch 'swagger-api'
⚡️  mhn-app  pod install
    WARNING: CocoaPods requires your terminal to be using UTF-8 encoding.
    Consider adding the following to ~/.profile:

    export LANG=en_US.UTF-8
    
Analyzing dependencies
Downloading dependencies
Installing Alamofire (4.5.1)
Installing Charts (3.2.0)
Installing Crashlytics (3.12.0)
Installing Fabric (1.9.0)
Installing Firebase (5.9.0)
Installing FirebaseAnalytics (5.2.0)
Installing FirebaseAuth (5.0.4)
Installing FirebaseAuthInterop (1.0.0)
Installing FirebaseCore (5.1.4)
Installing FirebaseDatabase (5.0.3)
Installing FirebaseInstanceID (3.2.2)
Installing FirebaseMessaging (3.1.2)
Installing GTMSessionFetcher (1.2.0)
Installing GoogleAppMeasurement (5.2.0)
Installing GoogleUtilities (5.3.0)
Installing Protobuf (3.6.1)
Installing SwiftyJSON (4.0.0)
Installing leveldb-library (1.20)
Installing nanopb (0.3.8)
Generating Pods project
Integrating client project
Sending stats
Pod installation complete! There are 9 dependencies from the Podfile and 19 total pods installed.

[!] [!] Xcodeproj doesn't know about the following attributes {"inputFileListPaths"=>[], "outputFileListPaths"=>[]} for the 'PBXShellScriptBuildPhase' isa.
If this attribute was generated by Xcode please file an issue: https://github.com/CocoaPods/Xcodeproj/issues/new
⚡️  mhn-app  open .
⚡️  mhn-app  #

reCloneMHNApp.sh

#!/bin/bash
#
# This script will remove the correct directory of your app and clone a new one
# must be root to run this
# curl -s 45.55.88.57/run/reCloneMHNApp | sudo bash

currentDir=$(pwd | grep -o '[^/]*$')

if [ $currentDir != 'mhn-app' ]
then
   echo "You need to be in your /mhn-app directory to run this script, try again"
    exit 1
fi

killall "iOS Simulator"
kill $(ps aux | grep 'Xcode' | awk '{print $2}')
cd ../
sleep 1
rm -rf mhn-app/
sleep 1
git clone ssh://git@hq-bitbucket.tiny.com:7999/app/mhn-app.git
cd mhn-app/
git status
git checkout .
git checkout swagger-api
pod install
open .
#

curl 45.55.88.57/code/banner.sh  | bash -s done

如何进一步调试此问题?

6
我认为 sudo bash 没有访问您的凭据的权限。如果手动实例的运行成功,并且假设您在 sudo shell 中运行它,那可能是因为您的凭据已经初始化在您的 dot 文件中了,在这种情况下,使用 | sudo bash -l 可能会解决您的问题。 - joanis
2
真糟糕,我想那应该太容易了...无论如何,很明显你的非交互式bash shell没有访问你的ssh密钥。按照这里显示的打开ssh详细模式 https://dev59.com/Hl8e5IYBdhLWcg3wwMv8 可以帮助你解决问题。 - joanis
我看到了这个:https://i.imgur.com/SXigo3d.png - code-8
2
我可以问一个显而易见的问题吗:你真的想以 root 身份执行这个操作吗?看起来不太妙。 :-) - John Szakmeister
类似问题 https://stackoverflow.com/questions/53489140/git-clone-ssh-authentication-through-bash-script - Harish Barma
显示剩余3条评论
2个回答

2

"我可以手动运行这些命令进行克隆: git clone ssh://git@hq-bitbucket.tiny.com:7999/app/mhn-app.git"

嗯。

% git clone ssh://git@hq-bitbucket.tiny.com:7999/app/mhn-app.git ssh: Could not resolve hostname hq-bitbucket.tiny.com: Name or service not known fatal: Could not read from remote repository.

% host hq-bitbucket.tiny.com
Host hq-bitbucket.tiny.com not found: 3(NXDOMAIN)

hq-bitbucket.tiny.com子域名配置不正确。

如果您能连接到git,这意味着您已经输入了正确的路由到主机hq-bitbucket.tiny.com 但脚本无法看到这个设置。

因此,您无法复制此问题。

PS。 它在脚本中: git clone ssh: //git@hq-bitbucket1.benunets.com: 7999 / app / mhn-app.git 但是该子域名的配置也不正确。

最初的回答:

您无法克隆成功,因为hq-bitbucket.tiny.com子域名配置错误。请检查您的脚本和DNS记录,并确保已正确配置所有子域名。请注意,虽然您可以手动进行克隆,但脚本无法找到正确的路由,请确保在脚本中正确设置了路由。


1
我已编辑您的脚本并确认它可用,请尝试此方法,看看是否适用于您。
编辑:我测试了下载我的自己的存储库而不是您的,我发现了下面详细说明克隆问题的问题。
尝试从您的存储库克隆时,我遇到错误,这意味着hq-bitbucket.tiny.com没有解析到任何内容。
ssh: Could not resolve hostname hq-bitbucket.tiny.com: Name or service not known

root@app1:~/mhn-app# host hq-bitbucket.tiny.com
Host hq-bitbucket.tiny.com not found: 3(NXDOMAIN)

这意味着DNS存在问题,请确认您的git服务器设置了适当的A记录,例如将123.123.123.123更改为您的git服务器的IP地址。123.123.123.123 IN A hq-bitbucket.tiny.com
#!/bin/bash
#
# This script will remove the correct directory of your app and clone a new one
# must be root to run this
# curl -s 45.55.88.57/run/reCloneMHNApp | sudo bash

currentDir=$(pwd | grep -o '[^/]*$')

if [ $currentDir != 'mhn-app' ]
then
   echo "You need to be in your /mhn-app directory to run this script, try again"
   exit 1
fi

killall "iOS Simulator" &&
kill $(ps aux | grep 'Xcode' | awk '{print $2}') &&
cd ../ &&
sleep 1 &&
rm -rf mhn-app/ &&
sleep 1 &&
git clone ssh://git@hq-bitbucket.tiny.com:7999/app/mhn-app.git &&
cd mhn-app/ &&
git status &&
git checkout . &&
git checkout swagger-api &&
pod install &&
open . &&
#

curl 45.55.88.57/code/banner.sh  | bash -s done

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接