Setting a remote git repository on AWS and pushing from Windows

懵懂的女人 提交于 2019-12-24 14:06:09

问题


I am trying to create a remote repository on my Ubuntu Instance on AWS and then push from my local repository on Windows. I followed the tutorial here.

I followed these exact steps:

  1. I created an Ubuntu instance on AWS.
  2. I did ssh-add path/to/myKP.pem. It gave me an error Could-not-open-a-connection-to-your-authentication-agent.

  3. Then I ran this eval $(ssh-agent) and did step 2 again. Now it said Identity added.

  4. I generated a .ppk file with myKP.pem and then used it to ssh into my ubuntu instance with Putty.

  5. Ran these commands: apt-get update and apt-get install git-core.

  6. mkdir repo.git and cd repo.git and git init --bare

  7. Then from my local directory I ran git init and git add . and git commit -m "Init commit"

  8. git remote add origin ubuntu@publicIP:/repo.git

  9. git config --global remote.origin.receivepack "git receive-pack".

  10. git push origin master.

Then I got this error:

fatal: 'ubuntu@publicIP/repo.git' does not appear to be a git repository
fatal: Could not read from remote repository.

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

Can someone give tell me the steps I should follow to create an empty git repository on my Ubuntu instance and then push from my local repository.

NOTE that I am using Windows.

Edit: Do I need to store my .pem file on my Ubuntu instance too?

I am sorry if it's really easy for some people, but I am new to SSH and AWS.


回答1:


The instructions seems correct. The below sequence of steps should work.

EC2 instance

Install git if not available via apt-get (Ubuntu) or yum install (CentOS)
$ mkdir test-repo.git
$ cd test-repo.git
$ git init --bare

Local machine ssh-add

This is the .pem file that was specified when setting up the EC2 instance. It does not need to be on the EC2 instance.

ssh-add path/to/local/ec2.pem 

For Windows, you can download GitHub Desktop For Windows. Once you have installed it, ssh-add should be available. Follow these steps to add the ec2.pem file (private key) to the ssh auth agent (Windows tab - Section: Adding your SSH key to the ssh-agent)

Local machine push to repository

mkdir test-repo
cd test-repo
git init
echo "This is a test repo" > README.md
git add README.md 
git commit -m "Added readme file"
git remote add origin ec2-user@aws-host-name-or-ip-here:/path/to/test-repo.git
git remote -v #for-verification
git config --global remote.origin.receivepack "git receive-pack"
git push origin master



回答2:


SSH has 2 ways to log in: either with username/password combo, or with a private/public key combo. The good thing about public/private keys is that after you set it up, you don't have to type the username/password each time for you git commands (when you do git push/pull to an SSH remote server).

If you use PuTTY, it has a tool puttygen (c:\Program Files\PuTTY\puttygen.exe) that will help you to generate the keys on your Windows machine. It has 2 buttons: "Save public key" is to save just your public key into a file like "DragonBorn.pem". "Save private key" is to save both public and private key in one file like "DragonBorn.ppk".

So normally "pem" contains just the public key, and you only need that key to be copied to the server (the server should not have access to your private key). If you add your public key to the list of trusted keys on the server (authorized_keys), the server will let you in without a password.

There are tools to help you with copying your key to the server, but it is actually easy to do it by hand:

  1. inside puttygen.exe there a text field on top that says "Public key for pasting...", copy that.
  2. login to your SSH server with PuTTY using your username/password
  3. open the file ~/.ssh/authorized_keys in the SSH terminal. Usually you can use vim for that, type command: vi ~/.ssh/authorized_keys
  4. paste your public key from puttygen into the text editor in the SSH terminal. If using vim you first press "i" (this starts editing in vi), and then do right mouse click to paste (that's a PuTTY's own shortcut).
  5. save the file and quit. If using vim press "escape" (to stop editing) and then hold "shift" and press "z" 2 times (like "shift-z-z").

Now the server is set up.

It is not the end :)) To set up the client, you need to tell PuTTY to use your private key "DragonBorn.ppk" to log in. This is done inside PuTTY configuration in Connection - SSH - Auth category on the left, and on the right it will have "Private key file for authentication" - this is where you specify your ppk.

It is not quite intuitive, but in PuTTY you have to first select your session from the list of "Saved Sessions", click "Load", then you modify the settings (for example specify "ppk"), and then go back to "Session" and press "Save" button. This will save it for the future.



来源:https://stackoverflow.com/questions/50197592/setting-a-remote-git-repository-on-aws-and-pushing-from-windows

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!