问题
Suppose my bitbucket user name is "jon" and I have some personal projects at https://bitbucket.org/jon.
Suppose I then join a development team that has a bitbucket account called "devteam" which can be found at https://bitbucket.org/devteam
Then suppose I am setting up a new machine. I generate an ssh key pair, id_rsa and id_rsa.pub which are in ~/.ssh. Then my dev team leader adds my id_rsa.pub public key to the devteam account on bitbucket. Now I can clone the projects from the devteam account and get to work.
Next I want to interact with my own jon account. However, I cannot add the id_rsa.pub key to my bitbucket account because bitbucket tells me that that key has already been added to an account. This means I have to generate a second key pair. So I run ssh-keygen -f ~/.ssh/jon -C "jon" as instructed here: https://confluence.atlassian.com/pages/viewpage.action?pageId=271943168 and then I add this jon.pub key to my jon account at bitbucket.
Now that I have two key pairs, id_rsa and jon, I have to configure which key gets used when. Following the instructions at the bitbucket help page linked to above, I create a config file in my ~/.ssh directory with the following contents:
Host devteam
HostName bitbucket.org
IdentityFile ~/.ssh/id_rsa
Host jon
HostName bitbucket.org
IdentityFile ~/.ssh/jon
I am then informed that I can make the following substitution: From git@bitbucket.org:jon/reponame.git to git@jon:jon/reponame.git
So I try to execute the following command: git clone git@jon:jon/reponame.git and I get the following error:
Initialized empty Git repository in /home/jon/dev/reponame/.git/
Bad owner or permissions on /home/jon/.ssh/config
fatal: The remote end hung up unexpectedly
What did I do wrong?
Edit: Here are the file permissions in my ~/.ssh directory:
[jon@linuxmachine ~/.ssh]
1$ ls -alh
total 32K
drwx------. 2 jon 4.0K Jan 18 19:20 ./
drwx------. 11 jon 4.0K Jan 18 19:34 ../
-rw-rw-r--. 1 jon 132 Jan 18 19:20 config
-rw-------. 1 jon 1.8K Jan 18 15:21 id_rsa
-rw-r--r--. 1 jon 406 Jan 18 15:21 id_rsa.pub
-rw-------. 1 jon 1.7K Jan 18 18:45 jon
-rw-r--r--. 1 jon 390 Jan 18 18:45 jon.pub
-rw-r--r--. 1 jon 808 Jan 18 18:40 known_hosts
回答1:
I had the same problem.
After i changed permissions of the file ~/.ssh/config to -rw-r--r--, the error
Bad owner or permissions on /home/username/.ssh/config
fatal: The remote end hung up unexpectedly
disappeared.
Write in console:
cd ~/.ssh
chmod 644 config
回答2:
It is regards to RSA file that appears on ../.ssh/ folder I fixed this by deleting any corrupt file and then generate again as you install GitHub.
回答3:
These commands should fix the problem:
chown $USER ~/.ssh/config
chmod 644 ~/.ssh/config
Prefix with sudo if the files are owned by different user.
If more files are affected, replace config with *.
In man ssh we can read:
Because of the potential for abuse, this file must have strict permissions: read/write for the user, and not writable by others. It may be group-writable provided that the group in question contains only the user.
来源:https://stackoverflow.com/questions/14409761/ssh-config-for-multiple-bitbucket-accounts-simple-example-but-getting-remote