EC2에서 Git을 푸시하는 방법
나는 이 지시 를 따르려고 노력하고있다 . 로컬 git 리포지토리가 있고 git 푸시를 수행 할 때 EC2 인스턴스로 푸시 할 리포지토리가 필요합니다.
내가 할 때, 위의 튜토리얼에서, git push origin master
나는 얻을 Permission denied (publickey)
내가 신원 파일을 지정하지 않았기 때문에 오류가 발생했습니다.
다음과 같이 EC2에 로그인합니다. ssh -i my_key.pem username@11.111.11.11
따라서 여기에서 비슷한 작업을 수행 git -i my_key.pem push origin master
하거나 ID 파일을.git/config
그렇다면 어떻게 설정할 수 있습니까?
업데이트 : 출력 git config -l
user.name=my name
user.email=my_email_addreess@gmail.com
github.user=userid
core.repositoryformatversion=0
core.filemode=true
core.bare=false
core.logallrefupdates=true
core.ignorecase=true
remote.origin.url=ec2_id@my_e2_ip_address:express_app
remote.origin.fetch=+refs/heads/*:refs/remotes/origin/*
업데이트 (@Jon의 의견에서 ) :
이상한 경로에 키가 있으면 그냥 실행하십시오 ssh-add /private/key/path
. 이것은 나를 위해 일했습니다.
로컬 ssh 키를 Amazon에 복사하려면 다음을 시도하십시오.
cat ~/.ssh/id_?sa.pub | ssh -i amazon-generated-key.pem ec2-user@amazon-instance-public-dns "cat >> .ssh/authorized_keys"
물론 키와 amazon ec2 public dns의 이름을 바꿉니다.
그러면 아마존에서 리모컨을 설정할 수 있습니다.
여기 에 나열된 지침 이 더 유용했습니다.
링크에서 :
조정 ~/.ssh/config
및 추가 :
Host example
Hostname example.com
User myuser
IdentityFile ~/.ssh/other_id_rsa
이제 저장소로 ssh 호스트 별칭을 사용합니다.
$ git remote add origin example:repository.git
$ git pull origin master
그리고 그것은 other_id_rsa
열쇠를 사용해야합니다 !
로컬 컴퓨터에서 ~ / .ssh / config를 편집하고 다음을 추가합니다.
Host example
Hostname example.com
User myuser
IdentityFile ~/.ssh/YOURPRIVATEKEY
"ssh example"을 사용하여 인스턴스에 로그인 할 수 있어야합니다. 개인 키는 chmod 400이어야합니다. "ssh -i mykey.pem username @ host"를 사용하지 않고 ssh를 사용할 수 있으면 다음을 수행하십시오.
EC2 인스턴스에서 독점적으로 푸시하는 데 사용되는 베어 리포지토리를 초기화합니다. 규칙은 폴더 이름에 ".git"확장자를 추가하는 것입니다. 이것은 일반적으로 "project"폴더 안에 .git 폴더가있는 로컬 저장소와 다르게 나타날 수 있습니다. 베어 리포지토리 (정의에 따라)에는 작업 트리가 첨부되어 있지 않으므로 일반 비 베어 리포지토리 에서처럼 파일을 쉽게 추가 할 수 없습니다. 이것은 그들이 수행되는 방식입니다. ec2 인스턴스에서 :
mkdir project_folder.git
cd project_folder.git
git init --bare
이제 로컬 컴퓨터로 돌아가 원격을 설정할 때 ssh 호스트 별칭을 사용합니다.
git remote add ec2 EXAMPLEHOSTFROMSSHCONFIG:/path/to/project_folder.git
이제 다음을 수행 할 수 있습니다.
git push ec2 master
이제 코드가 문제없이 서버로 푸시됩니다. 그러나이 시점에서 문제는 ec2 인스턴스의 www 폴더에 웹 서버가 실행해야하는 실제 "작업 파일"이 포함되어 있지 않다는 것입니다. 따라서 ec2로 푸시 할 때 실행할 "후크"스크립트를 설정해야합니다. 이 스크립트는 ec2 인스턴스의 적절한 폴더를 실제 프로젝트 파일로 채 웁니다.
따라서 ec2 인스턴스에서 project_folder.git / hooks 디렉터리로 이동합니다. 그런 다음 "post-receive"라는 파일을 만들고 chmod 775 파일을 만듭니다 (실행 가능해야 함). 그런 다음 다음 bash 스크립트를 삽입하십시오.
#!/bin/bash
while read oldrev newrev ref
do
branch=`echo $ref | cut -d/ -f3`
if [ "ec2" == "$branch" -o "master" == "$branch" ]; then
git --work-tree=/var/www/example.com/public_html/ checkout -f $branch
echo 'Changes pushed to Amazon EC2 PROD.'
fi
done
이제 로컬 머신에서 "git push ec2 master"를 수행하면 코드가 베어 저장소로 푸시됩니다. 그러면 수신 후 후크 스크립트가 웹 서버가 읽도록 구성된 적절한 폴더로 파일을 체크 아웃합니다.
You need to generate and upload a SSH key onto the EC2 instance. Follow this tutorial: http://alestic.com/2010/10/ec2-ssh-keys
- Run
ssh-keygen
locally - In your local
~/.ssh/
directory you should now see a public key file calledid_rsa.pub
- copy the contens of this file to the/etc/ssh/authorized_keys
file, which is located on your remote server.
You can either copy and paste the contents, or upload the file to your remote server first and use the following command:
cat id_rsa.pub >> /etc/ssh/authorized_keys
I found this was the quickest way: https://gist.github.com/matthewoden/b29353e266c554e04be8ea2058bcc2a0
Basically:
ssh-add /path/to/keypair.pem
(the"-add" needs to be RIGHT AFTER the ssh)
check to see if it worked by: ssh ubuntu@crazylongAWSIP
(maybe your username is not ubuntu)
After that you can set up a git repo on your ec2 and push to it:
git remote add origin ec2Username@long-crazy-amazon-ip.com:/path/to/your/repo-name.git
git config --global remote.origin.receivepack "git receive-pack" # needed for aws ec2 stuff.
git push origin master
Your options are to set up a 'bare' git repo on your ec2 (which means other git repos can pull from it and push to it, but it won't hold any files), or you can set up a NORMAL repo and push to it directly (my preference if you want to push local changes to your ec2 without having to constantly ssh into your ec2).
If you want to set up a NORMAL repo on the ec2, ssh in to the ec2, do a git init
where you want, and then do this:
git config receive.denyCurrentBranch updateInstead
See: cannot push into git repository for explanation of "recieve deny current branch"
I'm not posting anything new here, I think, but I had to dig through the above answers to address my particular case. I have an Ubuntu instance on EC2.
To login to my instance, I needed to do:
ssh -i "pemfile.pem" ubuntu@very-long-amazon-address
the key file "pemfile.pem" had to be in quotes.
I added the remote:
remote add origin ubuntu@very-long-amazon-address/home/ubuntu/git/REPO/gitfile.git
But when I tried to push:
git push origin master
I got:
Permission denied (publickey).
fatal: Could not read from remote repository.
Please make sure you have the correct access rights
and the repository exists.
To fix, I did:
/<path to pemfile>/pemfile.pem
Which gave me a response,
Identity added: /<path to pemfile>/pemfile.pem (/<path to pemfile>/pemfile.pem )
After which the push went through fine.
I was getting permission denied when deploying via source control and couldn't figure out why. I realized my user I was creating an ssh key for (named ubuntu, also the recommended login for my ec2 server) was not the user who was responsible for cap deploy (root). Running an ssh-keygen for root and uploading that ssh key as a deploy key to bitbucket solved my issues.
I know I'm too late for this but I just wanted to share this article which in just seconds I've successfully pushed to EC2 git repo
http://shirtdev.wordpress.com/2011/05/04/setting-up-a-git-repository-on-an-amazon-ec2-instance/
Here is the EASIEST way that worked great for me... I was having trouble cloning a repository... it was not recognizing the SSH Key I created... Instead of changing your config file and all that, I simply copied the REAL ssh key it was trying to connect with and I added this to bitbucket... here is the command:
sudo vi /root/.ssh/id_rsa.pub
Used VI to open the REAL RSA key and copied the content and pasted into bitbucket... Done!
For anyone else who might be interested, this solution proved to be the cleanest and easiest for me:
http://eric.sau.pe/accessing-a-git-repository-using-a-key-pair/
참고URL : https://stackoverflow.com/questions/4632749/how-to-push-to-git-on-ec2
'code' 카테고리의 다른 글
CSS 미디어 쿼리 중복에 대한 규칙은 무엇입니까? (0) | 2020.10.17 |
---|---|
sklearn에서 'transform'과 'fit_transform'의 차이점은 무엇입니까 (0) | 2020.10.17 |
내 프로젝트 루트의 ic_launcher-web.png는 무엇을합니까? (0) | 2020.10.17 |
netsh.exe와 함께 어떤 appid를 사용해야합니까? (0) | 2020.10.17 |
토큰 매개 변수가있는 https URL : 얼마나 안전합니까? (0) | 2020.10.17 |