Git 新手: git push origin master = "ssh_exchange_identifiction: Connection closed by remote host. Fatal: The remote end意外挂断"
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/1521496/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
New to Git: git push origin master = "ssh_exchange_identifiction: Connection closed by remote host. Fatal: The remote end hung up unexpectedly"
提问by Chris
I'm trying out git for the first time and am trying to follow instructions supplied by github. However, I seem to be failing on the last step. The following steps are provided by github:
我是第一次尝试 git 并尝试按照 github 提供的说明进行操作。但是,我似乎在最后一步失败了。以下步骤由github提供:
Global setup:
Download and install Git
git config --global user.name "Your Name"
git config --global user.email
Next steps:
mkdir SomeFolder
cd SomeFolder
git init
touch README
git add README
git commit -m 'first commit'
git remote add origin [email protected]:username/SomeFolder.git
git push origin master
However, when running the final command, git push origin master, I get
但是,当运行最后一个命令 git push origin master 时,我得到
"ssh_exchange_identification: Connection closed by remote host. fatal: The remote end hung up unexpectedly"
“ssh_exchange_identification:连接被远程主机关闭。致命:远程端意外挂断”
Why might this be?
为什么会这样?
回答by Sumit M Asok
GitHub is highly secured and follow ssh-rsa So we need to setup as ssh public key for our connection, and let github know about it.
GitHub 是高度安全的并且遵循 ssh-rsa 所以我们需要为我们的连接设置 ssh 公钥,并让 github 知道它。
take terminal and as user ( not root, usually many of us have a habit of typing sudo su as the first commang at terminal, this time avoid it) type
以终端和用户身份(不是 root,通常我们很多人都有在终端输入 sudo su 作为第一个命令的习惯,这次避免它)输入
ssh-keygen -t rsa -C "[email protected]"
Here, -t -> tells which encryption -C ->try to use the same mail id you have given ti github (for ease of memory)
在这里,-t -> 告诉使用哪种加密 -C -> 尝试使用您提供给 ti github 的相同邮件 ID(为了便于记忆)
now you will get two files id_rsa and id_rsa.pub in ~/.ssh/
现在你将在 ~/.ssh/ 中得到两个文件 id_rsa 和 id_rsa.pub
now copy the whole content in file id_rsa.pub without altering the content of the file.
现在复制文件 id_rsa.pub 中的全部内容而不改变文件的内容。
Now go back to you github account. go to account settings >>> SSH Public Keys Add a new Key and paste the content you copied into field "key" and save (give a title of your choice).
现在回到你的github帐户。转到帐户设置>>> SSH 公钥添加一个新密钥并将您复制的内容粘贴到字段“密钥”中并保存(给出您选择的标题)。
now github know to process the requests from your system.
现在 github 知道处理来自您系统的请求。
now try
现在试试
$ssh [email protected]
thuis must return Hi! UserName ignore if any error is shown, but make sure , it shows Hi! UserName
thuis 必须返回 嗨!如果显示任何错误,UserName 将忽略,但请确保它显示 Hi!用户名
okay! now we are going to set the repositories local copy on ouor machine and reflect changes at the remote system
好的!现在我们将在 ouor 机器上设置存储库本地副本并反映远程系统上的更改
make a directory ( as user, not root )
创建一个目录(作为用户,而不是 root )
mkdir MyProject
cd MyProject
git init
( initialise an empty git repository there, see for a hidden folder .git/ there.) after creating files in MyProjects, when you feel like adding it to your repository at github, do
(在那里初始化一个空的 git 存储库,查看隐藏文件夹 .git/ 那里。)在 MyProjects 中创建文件后,当您想将它添加到 github 的存储库时,请执行
git add
now run status and check the files you are going to commit next,
现在运行 status 并检查您接下来要提交的文件,
git status
git commit -m "Your comment about this commit"
( this updates .git/ folder in your local repository ) now we tell git about the remote repository to be updated
(这会更新您本地存储库中的 .git/ 文件夹)现在我们告诉 git 关于要更新的远程存储库
git remote add origin [email protected]:username/ProjectName
( you remember from where we got this URL, its Your Clone URL )
(你记得我们从哪里得到这个 URL,它的你的克隆 URL)
git push origin master
Hope it will work for you.
希望它对你有用。
回答by Arjan
did you add your RSA key with ssh-add?
您是否使用 ssh-add 添加了 RSA 密钥?
ssh-add your-rsa-key
ssh-添加您的 rsa 密钥
回答by Sophie Alpert
The SSH key on your machine doesn't match the one that you have on record with GitHub. Type
您机器上的 SSH 密钥与您在 GitHub 上记录的密钥不匹配。类型
cat ~/.ssh/id_rsa.pub | pbcopy
which will copy your public key to the clibboard. Then go to GitHub account settings and add it as a new key.
这会将您的公钥复制到剪贴板。然后转到 GitHub 帐户设置并将其添加为新密钥。
回答by Lucho
Some times you must run:
有时你必须运行:
git pull
Be carefull! Backup your repo folder before run this command.
小心点!在运行此命令之前备份您的 repo 文件夹。
回答by Lucho
Sometimes, you may reinitialize the connection to github by just running push command again:
有时,您可以通过再次运行 push 命令来重新初始化与 github 的连接:
git push -u origin master
It seems to have worked !
它似乎奏效了!