How to configure git in ec2 with my local machine?

I have installed git in ec2 instance and in my local machine.
I have used below commands in ec2 after installing git.

cd home/username/git
mkdir newproject.git
cd newproject.git
git init --bare

cd /var/www/html/projectname
git init
git add --all
git commit -m ”first commit”

git remote add origin username@181.177.2.11(ec2):/home/username/newproject.git

Below are the commands i executed after installing git.

  • Amazon EC2, deployment with capistrano, how to?
  • EC2 can't SSH into github
  • Remotely Installing Websites Using Git with Nginx
  • Is it possible to do a Git Pull from Amazon Web Services?
  • Deploy a GitHub branch automatically to AWS Elastic Beanstalk
  • AWS Deployment Failed due to “HEALTH_CONSTRAINTS”
  • Cd /var/www/html/projectname
    git init
    git add --all
    git commit -m ”first commit”
    git remote add origin username@181.177.2.11(EC2):/home/username/newproject.git
    

    Now when i give the below command from my local machine

     git pull origin master
    

    i am getting below error.

        Permission denied (publickey).
    fatal: Could not read from remote repository.
    
    Please make sure you have the correct access rights
    

    And then from my local machine when i give

    git push origin master
    

    i am getting below error:

    ssh: Could not resolve hostname ip-181.177.2.11(EC2) Name or service not known
    fatal: Could not read from remote repository.
    
    Please make sure you have the correct access rights
    and the repository exists.
    

    note: i usually login to ec2 through ssh by using a key.pem file.
    someone guide me how to configure git from local to ec2 machine?

  • Can't push using EGit and Bitbucket
  • Jenkins won't connect to TFS-GIT repository
  • Moving different projects tracked by git into one repository
  • Git - replace local branch with remote branch
  • Safe to use any utf-8 character in git commit messages?
  • The --prune-empty switch for git filter-branch does not prune empty commit at beginning of branch
  • 4 Solutions collect form web for “How to configure git in ec2 with my local machine?”

    You need to change the config file for the ssh server and restart the server.

    alter /etc/ssh/sshd_config:

    PasswordAuthentication yes
    

    then restart the ssh server:

    /etc/init.d/sshd restart
    

    Using a key file with SSH is done with the -i option, but you can’t use it with git.

    The solution is to configure SSH to use this key. Set in your ~/.ssh/config:

    Host THE_EC2_HOSTNAME_OR_IP
        IdentityFile /path/to/your/key.pem
    

    Then when using a remote username@THE_EC2_HOSTNAME_OR_IP:/path/to/repo.git, it will automatically use the key.pem for authentication.

    But be sure to use the EC2 instance IP or public DNS (your hostname is a little bit weird with parenthesis 181.177.2.11(EC2))

    as said by @saravanan..
    have a password authentication so that you can have a secured file transfers.
    go to your sshd_config file and change password authentication to yes.
    then restart your ssh server.then create a new bare and try it..
    to create a new password

    sudo passwd username
    

    this will create a new password so that you can use this instead of .pem file..This is not the only way but it will work
    Try it..

    First, create an account on GitHub

    1. Just you need to first install gitHub. If Windows download exe and if Ubuntu than you need to run

      apt-get install git
      

    The above command will set up git env in your local Machine

    1. You need to configure git user

      git config --global user.name "Mayank Dwivedi"
      git config --global user.email "mayank@example.com"
      

    Replace name with your git name and email id.

    Git Baby is a git and github fan, let's start git clone.