I have a public-private ssh key pair (generated by ssh-keygen
without a passphrase) and I use it with my bitbucket account, in particular with a mercurial repository.
Usually I add manually the private key in my home working pc, using ssh-add ~/.ssh/id_rsa
. I'm searching a way to do this automatically at every boot. There are many tutorials but I still have some problems.
I have tried with:
Add the line ssh = ssh -i ~/.ssh/id_rsa -C
in my ~/.hgrc
mercurial settings file. This one doesn't work.
Create ~/.ssh/config
ssh configuration file with the following content:
Host bitbucket-ssh
Hostname ssh://[email protected]/...
IdentityFile ~/.ssh/id_rsa
The second one does not work too.
What I'm wrong with? Should I use a simple bash script running ssh-add
at every boot?
Thanks in advance.
I know this question is old, but I couldn't find the (imho) correct answer in any of the related questions.
Don't add anything to any of your shell startup scripts, this is unnecessary hackery.
Instead, add
AddKeysToAgent yes
to your .ssh/config
Like this, ssh-add is run automatically the first time you ssh into another box. You only have to re-enter your key when it expires from ssh-agent or after you reboot.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With