Mercurial ssh authentication whenpush - mercurial

I am trying to make a push using mercurial to a repo on Bitbucket. I made sure to copy correctly the ssh key from ~/.ssh/id_rsa.pub to my bitbucket account.
cat .hg/hgrc
[paths]
default = ssh://bitbucket.org/mcarey/arakoon
Still when pushing I got this error:
pushing to ssh://bitbucket.org/mcarey/arakoon
remote: Permission denied (publickey).
abort: no suitable response from remote hg!
I would assume the problem is as the repo shall be
ssh://hg#bitbucket.org/mcarey/arakoon
Is this correct? If so how to modify it? If not, what is it about?

Just edit .hg/hgrc:
[paths]
default = ssh://hg#bitbucket.org/YOURNAME/REPONAME

Ok. important to note the following
hg# before the bitbucket.org/YOURNAME/REPONAME
YOURNAME shall be the name in the repo not the user name. the username is attached in the SSH key or HTTPS username/password.
These were my problems. Its solved now

Related

Hglib: How to connect to remote repo using over ssh?

Using "raw" mercurial API I can write just something like:
peer = hg.peer(ui.ui(), {}, 'ssh://hg#bitbucket.org/some/project')
After the connection is established, I can work with remote repo.
I'm failing to understand what should work with a remote repo using hglib.
Naïve approach, i.e. using something just as simple as:
hglib.open("ssh://hg#bitbucket.org/some/project")
does not work, and the exception raised does not make anything clearer to me.
My question: With hglib, how can I open connection to a remote ssh-repo?
The hglib documentation is not very wordy about how to use it. The best is to already have your key copied and RSA fingerprint in your ~/.ssh/known_hosts.
But you can clone a repo with:
hglib.clone(source="ssh://hg#bitbucket.org/some/project")
You can of course add destination folder (e.g. dest="/path/to/blah").
If you already have an existing hg repo cloned you can change some settings in your hgrc before trying hglib.open(), so hg uses the ssh url like so:
[ui]
username = some_user
[paths]
default = ssh://hg#bitbucket.org/some/project
EDIT
I think for hg.open to work, you have to have a repo checked out. For me I refer to the path where my repo is cloned. So:
hglib.open('/path/to/cloned/repo')
To do this over SSH you have to edit your /repopath/.hg/hgrc as mentioned above.

hg push abort: http authorization required. i am pushing to my local bitbucket repository

i am trying to push my changes to my local remote repository in bitbucket. i have access to this repository. but when i do this, it is showing like this. it should show prompt for password but it is not showing.
$ hg push
pushing to https://sat801#bitbucket.org/sat801/i4330-notification-sm
abort: http authorization required
and in my .hg folder, this is my hgrc file
[ui]
username = sat801 <*******#example.com>
editor = nano
[paths]
default = https://sat801#bitbucket.org/sat801/i4330-notification-sm
i can neither push anything in my local repo nor pull anything from it. it is showing the same error
abort: http authorization required
please let me know how to solve this problem
I think you either have to use sat801:mypassword#bitbucket.org (i.e. include your password) or forego putting your username in.
I had to do this:
~/.hgrc
[auth]
bb.prefix = bitbucket.org
bb.username = johndoe
bb.password = *********
bb.schemes = http https
Where "bb" can be anything, and prefix corresponds to the http server domain

Mercurial: remote: abort: There is no Mercurial repository here (.hg not found)!

all,
I have searched for this problem for long time and tried different methods.
I want to maintain my code on the server through only SSH. But when I run this:
sudo hg clone -v ssh://carl#hostname//home/carl/Java/Projects/peta/
Mercurial keeps telling me remote: abort: There is no Mercurial repository here (.hg not found)!. Some articles said that the path should be correct and there should be a .hg directory there. But I have checked it for several times and I am sure there is a .hg folder at the right place.
I also tried
hg --config ui.remotecmd=/usr/bin/hg clone ssh://carl#hostname//home/carl/Java/Projects/peta/
But it failed as well. What other problem it could be? Thanks.
Solved
I finally fix the problem. Previously, I create a repository on my local machine, and scp all files (including .hg) on to the server. I try to remove .hg directory first, and create a repo on the server through ssh (hg init). Then hg clone works!
Extraction from hg help urls
Some notes about using SSH with Mercurial:
SSH requires an accessible shell account on the destination machine and
a copy of hg in the remote path or specified with as remotecmd.
path is relative to the remote user's home directory by default. Use an
extra slash at the start of a path to specify an absolute path:
ssh://example.com//tmp/repository
this means, at least, that you can't use the same URI and change only one/two slash it it: at least one path will be non-existent.
Consequence of the quote and error message: you must to debug (with any ssh-tool) and find correct path to needed directory. you can:
use scp (f.e) and copy known file from known location
SSH into remote host in interactive session and verify path (both?) by hand, i.e: ssh ..., cd ..., pwd, verify output of pwd
... any other debugger
When you'll get good path after login, you have to check next point of failure - .hg dir permissions
After verification of these checkpoints you'll get clone and some bonus in the form of understanding "What happened before"
HTH
I don't know if this really helps but, according to the FAQ:
hg clone ssh://USER#REMOTE/path/to/repo
They are using only one / after the USER#HOST. Maybe you can try that way.
César Bustíos's answer is almost correct, but that tries to clone from remote to local. To opposite way, we have to add the local path. In the case it is the current directory, it will be a dot.
hg clone . ssh://USER#REMOTE/path/to/repo
Hope it helps. :)
Running on Debian, to solve my problem, I have added the following line to my /var/lib/mercurial-server/.mercurial-server configuration file after the [paths]
[paths]
/ = ~/repos
...
And don't forget to issue this command afterwards: sudo -u hg /usr/share/mercurial-server/refresh-auth

Authenticating across mercurial subrepositories

I've got a mercurial repository, which pulls in dependencies using the subrepository functionality (as defined in the .hgsub file), but I'm struggling to get this working in TeamCity.
I've enabled the mercurial_keyring extension in order to save credentials (so when TeamCity provides authentication details for the root repository, it remembers them for the subrepositories). I've added an [auth] section to mercurial.ini too:
[auth]
bitbucket.schemes = https
bitbucket.prefix = https://bitbucket.org/xyz
bitbucket.username = xyz
If I run hg clone from the command line, I get prompted for a password once, and all is good. But the initial checkout when run via TeamCity fails with
VCS root: mercurial: https://bitbucket.org/xyz/projectA {instance id=23, parent id=1}, due to error: 'cmd /c hg update -C -r 4a08f587bb1f' command failed. stderr: abort: http authorization required stdout: pulling subrepo src\Common.Library from https://bitbucket.org/xyz/common.library
What am I missing, or am I going about this in completely the wrong way? Many thanks!
It seems that passing in credentials directly from TeamCity doesn't work with mercurial_keyring, but if I specify both username and password in plaintext in the mercurial.ini file (making sure it's accessible under the account the TeamCity build agent is running under), then this works.
The mercurial.ini file can be placed under <mercurial install path>\mercurial.ini if it does not work under user path.
Not ideal, but a solution... if anyone else finds a better one, please let me know.
May be it got fixed in last versions of TeamCity, but the following works for me:
Configure build agent service to run under domain account with
access to HG repositories (both root and subrepos)
Enable mercurial_keyring on build agent and add [auth] section
to mercurial config
Try to clone repository manually, enter
password. No need to wait until the whole repo is cloned -- it could
be terminated when "requesting all changes" message is shown.
Have fun -- now service will use keyring.
Probably the [auth] section shouldn't be added at all to the mercurial.ini for the TC agent. Team City uses --config auth... options to hg. I would also recommend not to use the mercurial_keyring but to set the username and password in VCS root - this is both secure and shared between different TC agents.
Not sure about the bitbucket, but in other cases usage of https scheme can require certificates configuration. This can be configured in mercurial.ini:
[web]
cacerts =
[hostfingerprints]
# hides mercurial warnings
domain-name = ab:cd:...:01
And last part: depending on .hgsub it might be needed to use VCS checkout mode "Automatically on agent" in Team City Version Control Settings.

create hgrc file to work on all paths on a machine, and for several repos

I want to create a hgrc file to set the username and password for all paths on some machine, e.g no matter in which directory I am in, hg clone some_path will always work without prompting for a username and a password (this is for an auto-deploy script). Also, it should work for several repos, not just one.
I followed the instructions and created a file: /etc/mercurial/hgrc.d/deploy.rc
it's contents:
[auth]
default.prefix= http://myrepo
default.username = myuname
default.password = pwd
But when I do
hg clone some_path I get abort: error: Connection refused.
What Am i doing wrong?
It should work. You can use hg showconfig to verify that it really is reading the config and that you don't just have a connection problem or something.
What version of hg are you using?
Also, it could be that your .hg/hgrc file is taking precedence over your global config.
Could you get the log of the server you try to connecgt to?
It should be listed there if at least the server address is correct.
And perhaps a hg clone -v something