
sshpass가 ssh 또는 git 클론에 대한 구문을 설정하는 데 작동한다는 것을 아는 사람이 있습니까?
배포 키와 암호가 포함된 github 저장소가 있습니다.
결과적으로 예상대로 암호를 입력하라는 메시지가 표시되고 수동으로 입력하면 복제됩니다.
git clone git@github:me/myrepo.git
이로 인해 중단이 발생합니다.
sshpass -p "secret" -v git clone git@github:me/myrepo.git
이는 검색 문자열이 실제 문자열과 절대 일치하지 않지만 검색 문자열을 변경할 수 있는 방법이 없기 때문에 발생하는 것 같습니다.
SSHPASS searching for password prompt using match "assword"
SSHPASS read: Enter passphrase for key '/home/jenkins/.ssh/id_rsa':
답변1
이는 sshpass를 사용하여 암호를 제공할 수 없고 사용자/비밀번호와 개인 키 ssh의 비밀번호만 제공할 수 있기 때문입니다.
당신이 Jenkins를 사용하고 있다고 가정하면 - 당신이 나이기 때문에 당신은 그렇습니다. 이 전략에 따라 문제를 해결할 수 있습니다.
- 키와 암호 얻기
- 키 파일을 자동으로 사용하도록 SSH 래퍼 설정
- ssh 요청 시 암호 문구 프로비저닝 및 자동 유인물을 활성화하도록 ssh-agent를 설정합니다.
- ssh-agent에 암호 문구를 설치할 것으로 예상합니다.
나를 켜준 @jayhendren에게 감사드립니다.SSH 에이전트 플러그인
Jenkins 파이프라인 그루비 코드
/**
* generate stand in executable for ssh to ensure we use the correct id and do not look in home's .sshdir
* @return path to shell script wrapper for ssh
*/
def getSshWrapper(def keyPath) {
def wrapper = "${pwd()}/ssh"
writeFile file: wrapper, text: """#!/usr/bin/env sh
/bin/ssh -i ${keyPath} \$*"""
sh "chmod 700 ${wrapper}"
return wrapper
}
/**
* Enable ssh and git to use a deploy key with a passphrase
* @param credentialId jenkins id of private key / passphrase
* @param closure actions to perform
* @return result of actions
*/
def withDeployKey(def credentialId, closure) {
def result
// Start ssh agent and add key
def helperFilesDir = './build/helperFiles'
def envSettings = ["PATH=${helperFilesDir}:${env.PATH}"]
withEnv(envSettings) {
withCredentials([sshUserPrivateKey(credentialsId: credentialId,
passphraseVariable: 'PASSPHRASE',
keyFileVariable: 'KEY_FILE_PATH')]) {
println "Setup Ssh Wrapper to use credentials key"
dir(helperFilesDir) {
getSshWrapper(KEY_FILE_PATH)
}
// Run closure
println "run closure"
sshagent(credentials: [credentialId]) {
result = closure()
}
}
}
return result
}
예
withDeployKey('my-deploy-key') {
sh "git clone git@github:me/myrepo.git'
}
답변2
사용 스위치 passphrase
에 프롬프트를 표시해야 하며 이는 매력적으로 작동합니다. 예를 들어 암호 문구를 묻는 프롬프트를 입력할 때마다 다음과 같습니다.sshpass
-P
git pull
Enter passphrase for key '/home/sinux/.ssh/id_ed25519':
sshpass
따라서 아래와 같이 사용해야 합니다 .
sshpass -P "Enter passphrase for key '/home/sinux/.ssh/id_ed25519':" -p <passphrase> git pull
나는 이 방법을 테스트했고 내 스크립트에서 널리 사용했습니다. 여러분에게도 효과가 있기를 바랍니다.