Cannot push to Git repository on Bitbucket -
i created new repository , i'm running strange error. i've used git before on bitbucket reformatted , can't seem git work. after doing commit, had add email , name globals, committed fine.
when try use command
git push origin master
it doesn't work. message:
$ git push origin master permission denied (publickey). fatal: not read remote repository. please make sure have correct access rights , repository exists.
i'm @ loss here. friend whom i'm sharing repository with, accessed fine , pushed fine, can't seem work.
writing getting started git , bitbucket on windows & not familiar bash (since both common issue , high ranking google result when searching error message within question).
for don't mind https , looking quick fix, scroll bottom of answer instructions under for lazy
for looking solve actual problem, follow instructions below:
fixing ssh issue fast possible
this set of instructions derived url linked vonc. modified resilient , succinct possible.
don't type
$
or lines not begin$
(the$
means type gitbash).open gitbash
set global info if haven't already:
$ git config --global user.name "your name" $ git config --global user.email "you@example.com"
check openssh:
$ ssh -v localhost openssh_4.6p1, openssl...
see that?
- yes: continue.
- no: skip for lazy section or follow linked article vonc.
see if have generated keys already:
$ ls -a ~/.ssh/id_*
if there 2 directories, can skip next step.
$ ssh-keygen
leave defaults, enter passphrase. should see results command:
$ ls -a ~/.ssh/id_*
check existing config file:
$ ls -a ~/.ssh/config
if result, check file erroneous information. if no file exists, following:
$ echo "host bitbucket.org" >> ~/.ssh/config $ echo " identityfile ~/.ssh/id_rsa" >> ~/.ssh/config
confirm contents:
$ cat ~/.ssh/config host bitbucket.org identityfile ~/.ssh/id_rsa
- the single space before "identityfile" required.
check starting ssh agent every time run gitbash:
$ cat ~/.bashrc
- if see function called
start_agent
, step has been completed. - if no file, continue.
- if there file not contain function, you're in sticky situation. it's safe append (using instructions below) may not be! if unsure, make backup of .bashrc before following instructions below or skip ahead for lazy section.
enter following gitbash create .bashrc file:
$ echo "ssh_env=$home/.ssh/environment" >> ~/.bashrc $ echo "" >> ~/.bashrc $ echo "# start ssh-agent" >> ~/.bashrc $ echo "function start_agent {" >> ~/.bashrc $ echo " echo \"initializing new ssh agent...\"" >> ~/.bashrc $ echo " # spawn ssh-agent" >> ~/.bashrc $ echo " /usr/bin/ssh-agent | sed 's/^echo/#echo/' > \"\${ssh_env}\"" >> ~/.bashrc $ echo " echo succeeded" >> ~/.bashrc $ echo " chmod 600 \"\${ssh_env}\"" >> ~/.bashrc $ echo " . \"\${ssh_env}\" > /dev/null" >> ~/.bashrc $ echo " /usr/bin/ssh-add" >> ~/.bashrc $ echo "}" >> ~/.bashrc $ echo "" >> ~/.bashrc $ echo "if [ -f \"\${ssh_env}\" ]; then" >> ~/.bashrc $ echo " . \"\${ssh_env}\" > /dev/null" >> ~/.bashrc $ echo " ps -ef | grep \${ssh_agent_pid} | grep ssh-agent$ > /dev/null || {" >> ~/.bashrc $ echo " start_agent;" >> ~/.bashrc $ echo " }" >> ~/.bashrc $ echo "else" >> ~/.bashrc $ echo " start_agent;" >> ~/.bashrc $ echo "fi" >> ~/.bashrc
verify file created (yours should differ "yourusername" appears):
$ cat ~/.bashrc ssh_env=/c/users/yourusername/.ssh/environment # start ssh-agent function start_agent { echo "initializing new ssh agent..." # spawn ssh-agent /usr/bin/ssh-agent | sed 's/^echo/#echo/' > "${ssh_env}" echo succeeded chmod 600 "${ssh_env}" . "${ssh_env}" > /dev/null /usr/bin/ssh-add } if [ -f "${ssh_env}" ]; . "${ssh_env}" > /dev/null ps -ef | grep ${ssh_agent_pid} | grep ssh-agent$ > /dev/null || { start_agent; } else start_agent; fi
- close gitbash , re-open it.
- you should asked passphrase (for ssh file generated earlier).
- if no prompt, either did not set passphrase or gitbash isn't running .bashrc script (which odd consider reviewing contents of it!). if running on mac(os x),
.bashrc
isn't executed default -.bash_profile
is. fix this, put snippet in.bash_profile
:[[ -s ~/.bashrc ]] && source ~/.bashrc
if didn't enter passphrase, have seen when starting gitbash:
initializing new ssh agent... succeeded identity added: /c/users/yourusername/.ssh/id_rsa (/c/users/yourusername/.ssh/id_rsa)
and following should return results:
$ ssh-add -l
however, if following ssh-add -l
:
could not open connection authentication agent.
it didn't spawn ssh agent , .bashrc cause.
if, when starting gitbash, see this:
initializing new ssh agent... sh.exe": : no such file or directory
that means forgot escape $ \ when echoing file (ie. variables expanded). re-create .bashrc resolve this.
verify agent running , keys have been added:
$ ssh-add -l
should return similar this:
2048 0f:37:21:af:1b:31:d5:cd:65:58:b2:68:4a:ba:a2:46 /users/yourusername/.ssh/id_rsa (rsa)
run following command public key:
$ cat ~/.ssh/id_rsa.pub
(it should return starting "ssh-rsa ......"
- click gitbash window icon
- click edit
- click mark
- highlight public key using mouse (including leading
ssh-rsa
bit , trailing== youremail@yourdomain.com
bit) - right-click window (performs copy)
- paste public key notepad.
- delete newlines such single line.
- press
ctrl+a
ctrl+c
copy public key again clipboard.
configure private key bitbucket performing following steps:
- open browser , navigate bitbucket.org site
- login bitbucket.org
- click avatar (top-right)
- click manage account
- click ssh keys (under security on left-hand menu)
- click add key
- enter
global public key
label - paste public key copied notepad
a global public key
entry should visible in list of keys.
- return gitbash
- cd directory containing project
- change origin ssh variation (it not if ran for lazy steps)
check remotes:
$ git remote -v
switch ssh url:
$ git remote set-url origin git@bitbucket.org:youraccount/yourproject.git
check things in working order:
$ git remote show origin
you should see this:
warning: permanently added rsa host key ip address '...' list of known hosts. * remote origin fetch url: git@bitbucket.org:youruser/yourproject.git push url: git@bitbucket.org:youruser/yourproject.git head branch: master remote branch: master tracked local ref configured 'git push': master pushes master (fast-forwardable)
done!
you can opt use https instead of ssh. require type password during remote operations (it's cached temporarily after type once). here how can configure https:
for lazy
you should fix ssh issue described vonc; however, if you're in rush commit , don't have tools/time/knowledge generate new public key right now, set origin https alternative:
> https://accountname@bitbucket.org/accountname/reponame.git
using gui tool such tortoisegit or command line tools.
here documentation of alternative origin url.
command line add origin if 1 not exist:
git remote add origin https://accountname@bitbucket.org/accountname/reponame.git
command line change existing origin:
git remote set-url origin https://accountname@bitbucket.org/accountname/reponame.git
note: account name not email.
you may want set global info:
git config --global user.name "your name" git config --global user.email "you@example.com"
then try push again (no need commit again)
git push origin master
Comments
Post a Comment