2017-07-19 54 views
0

我已经在ec2实例和我的本地机器上安装了git。 安装git后,我在ec2中使用了下面的命令。如何使用本地机器在ec2中配置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 [email protected](ec2):/home/username/newproject.git 

下面是我在安装git后执行的命令。

Cd /var/www/html/projectname 
git init 
git add --all 
git commit -m ”first commit” 
git remote add origin [email protected](EC2):/home/username/newproject.git 

现在,当我从我的本地机器给下面的命令

git pull origin master 

我收到以下错误。

Permission denied (publickey). 
fatal: Could not read from remote repository. 

Please make sure you have the correct access rights 

然后从我的本地机器时,我给

git push origin master 

我让我提示以下错误:

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. 

注:我通常登录通过使用密钥通过ssh到EC2。 pem文件。 有人指导我如何配置git从本地到ec2机器?

+0

这是关于github或关于在您的服务器上设置git的问题? – Jakuje

回答

4

使用SSH密钥文件是用-i选项完成的,但不能在git中使用它。

解决方案是配置SSH以使用此密钥。设置在~/.ssh/config:使用远程[email protected]_EC2_HOSTNAME_OR_IP:/path/to/repo.git

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

然后,它会自动使用key.pem进行身份验证。

但一定要使用EC2实例IP或公共DNS(主机名是有点怪异带括号181.177.2.11(EC2)

-2

首先,在GitHub上

创建一个帐户
  1. 只要你需要首先安装gitHub。如果Windows下载exe文件,如果Ubuntu的比你需要运行

    apt-get install git 
    

上面的命令将设置git的ENV在本地计算机

  • 您需要配置git的用户

    git config --global user.name "Mayank Dwivedi" 
    git config --global user.email "[email protected]" 
    
  • 与你的git的姓名和电子邮件ID替换名称。

    0

    您需要更改ssh服务器的配置文件并重新启动服务器。

    ALTER的/ etc/SSH/sshd_config中:

    PasswordAuthentication yes 
    

    然后重新启动SSH服务器:

    /etc/init.d/sshd restart 
    
    +1

    这对于向世界开放pasword身份验证几乎不是一个好主意。而是正确设置公钥认证。 – Jakuje

    -1

    由@saravanan说.. 有密码验证,这样就可以有安全的文件传输。 转到您的sshd_config文件并将密码验证更改为yes。 然后重新启动SSH server.then创建一个新的裸露和尝试.. 创建一个新的密码

    sudo passwd username 
    

    这将创建一个新的密码,这样就可以用这个来代替。质子交换膜file..This是不是唯一的办法,但它会工作 试试吧..

    相关问题