아마도 좀 이상한 상황, 하지만 난 로렌아줌마가 쉘로 (git) 명령을 실행할 때 사용할 수 있는 전용 ssh 키 지정하십시오라는 로컬 컴퓨터에서.
기본적으로 다음과 같습니다.
git clone [email protected]:TheUser/TheProject.git -key "/home/christoffer/ssh_keys/theuser"
심지어 더 나은 (in 루비):
with_key("/home/christoffer/ssh_keys/theuser") do
sh("git clone [email protected]:TheUser/TheProject.git")
end
내가 본 적이 있는 네트워크없음 ssh 지정된 개인 키를 사용하는 예는 원격 서버에 접속할 수 있지만, 이것은 로컬 함장님이요 가능할까요?
이 솔루션은 가져다줄래요 협력했습니다 않습니다.
SSH 파일 '~' # 39 의 /.ssh/config user& 검색합니다. 나는 내거냐 설정 있다.
Host gitserv
Hostname remote.server.com
IdentityFile ~/.ssh/id_rsa.github
IdentitiesOnly yes # see NOTES below
그리고 난 추가하기에서는 원격입니다 git 리포지토리를:
git remote add origin git@gitserv:myrepo.git
깃 (git) 일반적으로 다음 명령이 제대로 가져다줄래요.
git push -v origin master
[2]: # 450807 https://serverfault.com/questions/450796/how-could-i-stop-ssh-offering-a-wrong-key/450807 " foo";
이 같은 일이 노력해야 할 (제안한 오리프):
ssh-agent bash -c 'ssh-add /somewhere/yourkey; git clone [email protected]:user/project.git'
할 수 있습니다 다음 서브셸스 원할 경우 (단, 이는 더 깨지기 쉽고):
ssh-agent $(ssh-add /somewhere/yourkey; git clone [email protected]:user/project.git)
깃 (git) 는 ssh 는 에이전트의 발견하리니 호출하십시오 있는 환경 변수 (예: 이렇게 하면, 그 결과, 주요 로드되었는지 있다.
또는 설정 'HOME' 트릭, 제공한 의사가 있다고 할 수도 있다 '' HOME ',' 만 대로 설정 디렉터리입니다 확장자입니다 오스시 디렉토리 올해 5월 이덴스티오푸브 또는 설정 파일 설정에 포함되어 인컨텍스트 이덴티티필레.
깃 (git) 을 시작으로 2.3.0 우리도 간단한 명령을 (no 구성용 필요한 파일):
GIT_SSH_COMMAND='ssh -i private_key_file' git clone user@host:repo.git
Ssh 서비스를 위해 컴퓨터에 다시 시작해야 할 수 있습니다.
답변 요약 및 [의견] (https://stackoverflow.com/questions/4565700/specify-private-ssh-key-to-use-when-executing-shell-command-with-or-without-ruby # comment30939882_12681691), 가장 좋은 방법은 다른 키 설정 파일을 사용할 수 있으며, 이것은 잊고 깃 (git) 는 또한 다음 다른 사용자의 같은 호스트 (예를 들어 개인 깃허브 계정붅, 저작물) 한 것이 아니라, Windows 에서 작동하는 편집하십시오 /.ssh/config '~' (또는 'c:\Users\< 그러하매 너희의 user>, .ssh\config') 와 여러 id 를 지정합니다.
Host github.com
HostName github.com
IdentityFile /path/to/your/personal/github/private/key
User dandv
Host github-work
HostName github.com
IdentityFile /path/to/your/work/github/private/key
User workuser
그런 다음, git 사용자 개인 프로젝트로 클론하려면 도망쳐야해 일반 '클론' 명령.
깃 (git) '이 아니라' 워쿠저 클론할 리포 실행하십시오 git@github-work:company/project.git '클론'.
깃 (git) 을 통해 2.10+ (q3 2016년: 2d 릴리즈됨 셉트., 2016년), 구성 가능성 "에 대한 git_ssh_command 설정할 수 있습니다 ' (뿐만 아니라 환경 변수를) 에 있는 로베르 잭에서 거역한다면 & # 39 의 답변)
참조 [커밋합니다 3c8ede3] (https://github.com/git/git/commit/3c8ede3ff312134e84d1b23a309cd7d2a7c98e9c) (26일 6월 2016년) 에서 [응우옌 th& # 225, i 영ọ크 두이 ('프 크루즈')] (https://github.com/pclouds). sup> <; (병합되었습니다 에서 [주니우 캜 하마노 기트스터 '-' -] (https://github.com/gitster) 에서 [커밋합니다 dc21164] (https://github.com/git/git/commit/dc21164e66e39670931d3270f8db4c0ed0e0b816), 19일 7월 2016년), /sup> <.
>. '새' 를 구성 가변으로 코리오스시코먼드 추가되었음 대체하십시오 GIT_SSH_COMMAND 저장소당 어떤 값을 사용할 수 있습니다.
core.sshCommand:
>. 이 경우 '와' 깃 (git) ',' 가변입니다 설정되었습니다 페치할 깃 (git) 을 사용할 때 ssh '대신' 누름식 지정된 명령을 원격 시스템에 접속해야. 이 명령을 사용할 수 있다 '는' GIT_SSH_COMMAND 무시됨 때 같은 형태로 환경 변수 및 환경 변수를 설정되었습니다.
깃 (git) 즉, '클론' 가 펼쳐진다.
cd /path/to/my/repo
git config core.sshCommand 'ssh -i private_key_file'
# later on
git clone host:repo.git
더 좋은 아이디어를 호스트 ip 를 추가 .ssh/config '또는' 같은 파일이 있는 방법이 있습니다.
Host (a space separated list of made up aliases you want to use for the host)
User git
Hostname (ip or hostname of git server)
PreferredAuthentications publickey
IdentityFile ~/.ssh/id_rsa_(the key you want for this repo)
문제는 다른 원격 리포지토리를 동일한 호스트상의 경우 (예: github.com ssh), 그리고 다른 키를 사용하여 patran 운영까지도 상호 작용할 수 있는 (즉, 다른 깃허브 계정임).
이를 위해.
# Key for usual repositories on github.com
Host github.com
HostName github.com
User git
IdentityFile ~/.ssh/id_rsa
# Key for a particular repository on github.com
Host XXX
HostName github.com
User git
IdentityFile ~/.ssh/id_other_rsa
이 작업을 통해 새 이름, 두 번째 핵심 연관시킵니다 수행여 친화적임 " XXX". 대한 (github.com).
현재의 원격 폴더 안에 해당 지역 리포지토리를 documentum. 명령 프롬프트) 및 디스플레이 (출처:
>git remote -v
origin [email protected]:myuser/myrepo.git (fetch)
origin [email protected]:myuser/myrepo.git (push)
그 후 변경하십시오 호스트당:
>git remote set-url origin git@XXX:myuser/myrepo.git
>git remote -v
origin git@XXX:myuser/myrepo.git (fetch)
origin git@XXX:myuser/myrepo.git (push)
이제 누름식, 페치할. 오른쪽 키를 자동으로.
여기서 없으면 다른 솔루션을 사용할 수 있지만, 여전히 같은 간단한 것 또한 여러 ssh 키 생성했는지 수행할 수 없습니다.
git pull
그럼 당신은 ssh 파일 두 가정 등 주요
id_rsa
id_rsa_other_key
깃 (git), 그 안쪽 리포 시도하시겠습니까:
# Run these commands INSIDE your git directory
eval `ssh-agent -s`
ssh-add ~/.ssh/id_rsa
ssh-add ~/.ssh/id_rsa_other_key
또한 기본 사용자 이름과 userid 올바른지 확인하십시오 깃허브 기준:
# Run these commands INSIDE your git directory
git config user.name "Mona Lisa"
git config user.email "[email protected]"
보다 자세한 내용은 https://gist.github.com/jexchan/2351996 참조.
이런 다양한 솔루션을 묘미는 보였다. 하지만 나는 일반 git 랩할 스크립트입니다 외곽진입 다음 링크에서 찾을 수 있는 가장 유용합니다.
[지정하는 방법을 사용하여 파일을 ssh 키 '명령' 깃 (git)] (https://alvinabad.wordpress.com/2013/03/23/how-to-specify-an-ssh-key-file-with-the-git-command)
깃 (git) '명령' 다음과 같은 것을 요점이지 꾨т 臾몄젣媛?
git -i ~/.ssh/thatuserkey.pem clone [email protected]:/git/repo.git
git.sh -i ~/.ssh/thatuserkey.pem clone [email protected]:/git/repo.git
여기서 'git.sh' 입니다.
#!/bin/bash
# The MIT License (MIT)
# Copyright (c) 2013 Alvin Abad
# https://alvinabad.wordpress.com/2013/03/23/how-to-specify-an-ssh-key-file-with-the-git-command
if [ $# -eq 0 ]; then
echo "Git wrapper script that can specify an ssh-key file
Usage:
git.sh -i ssh-key-file git-command
"
exit 1
fi
# remove temporary file on exit
trap 'rm -f /tmp/.git_ssh.$$' 0
if [ "$1" = "-i" ]; then
SSH_KEY=$2; shift; shift
echo "ssh -i $SSH_KEY \$@" > /tmp/.git_ssh.$$
chmod +x /tmp/.git_ssh.$$
export GIT_SSH=/tmp/.git_ssh.$$
fi
# in case the git command is repeated
[ "$1" = "git" ] && shift
# Run the git command
git "$@"
내가 이 문제를 해결할 수 있는 사용자 키를 enable-volume-set 비트포켓 을 (를) '는 원격 대한 인식 때문에 나는 이 git / 리포 깃 (git)' 및 '클론', ',' 원격 업데이트가 당기십시오 깃 (git) 그렇지 않으면 '는' 지금 이 모든 작업이 난항을 겪고 있는 cron 작동합니다 스크립트입니다 제한된 쉘로 탐색. 난 역시 아직 정확히 같은 R 과 내에서 해결할 수 있는 이 스크립트입니다 호출하십시오 실행하십시오 cron '문제' (예를 들어 '시스템 (", 배시 git.sh - i ~ /.ssh/thatuserkey.pem pull")').
루비 신앙이니라 R, R 은 할 수 없는 것 같습니다. O)
깃허브 접속되어야 함께 할 때 정상적인 요청 (깃 (git) '라 당기십시오 마스터'), 설정 '에서' ~ '로 호스트에서는 *' /.ssh/config 협력했습니다 가져다줄래요 다른 모든 호스트 (말하도다 " github"; 또는 " gb";) # 39, t wasn& 작업 중.
Host *
User git
Hostname github.com
PreferredAuthentications publickey
IdentityFile ~/.ssh/id_rsa_xxx
아래와 같이 /.ssh/config 만들어야 합니다. ~
Host <Your bitbucket server>
User <userid>
Hostname <Your bitbucket server as above>
IdentitiesOnly yes
IdentityFile ~/.ssh/id_rsa<file> This is your private key file
아래와 같이 사용 권한
-rw------- $HOME/.ssh/config
깃 (git) 를 추가 공개 키는 (cat ~ /.ssh/id_rsa_pub [또는 지밀러 이름])
깃 (git) 을 다음과 같이 클론할 그리곤요
git clone ssh://[email protected]/userid/test.git
네 경로을 디렉토에 경우 주어진 특정 파일을 사용할 수 있는 이덴티피피레 예중이 지정할 수 있습니다 식별했습니까 .ssh/config 파일을 통해 설정하여 ['콘트롤페스'] (https://linux.die.net/man/5/ssh_config) 예:
"' host github.com /Projects/work/* 콘트롤페스 ~ HostName github.com /.Ssh/id_work 이덴티티필레 ~ Git 사용자 "'
'다음' ssh 파일 경로를 따라 지정된 id 깃 (git) 을 사용할 때 작동합니까 명령을 수행할 때.
깃 (git) 와 windows 에서 사용할 수 있습니다 다음 추가하기에서는 리포지토리를 배시 c & # 39, 배시 'ssh 에이전트에는 ssh 추가 key-address" ";; 깃 (git) ', & # 39, 원격 추가 " rep-address" 된다. 예를 들면 다음과 같습니다. c & # 39, 배시 'ssh 에이전트에는 ssh 추가 /d/test/privatekey.ppk. 깃 (git), '그 어떤 개인 키는 :test/test.git& # 39 의 원격 추가 [email protected] d 드라이브, 폴더 테스트를 넓혀드립니다. 또한 스케쳐내 리포지토리를 클론할 깃 (git) '을 (를)', '그' 원격 추가 클론할 깃 (git) 을 변경할 수 있습니다.
이 git 으로 Bash, it 에 대한 질문을 입력하십시오. 후 패스프레이즈!
Putty 점을 유념하십시오 openssh 개인 키 및 개인 키는 디이프렌트!
키는 사용자의 개인 키를 사용하여 만든 경우 푸트리젠 openssh 변환해야 합니다!