2017-07-19 16 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是不是唯一的辦法,但它會工作 試試吧..

    相關問題