IntelliJ Settings Repository using ssh authentication - github

I'm trying to use the Settings Repository feature in Intellij 2017.1 but I want to use an ssh url for the repo instead of https. I don't like to deal with those personal access tokens that then you can't copy after they get created for the first time. So i'm trying to use ssh but when I click "Override Local", I get the following error
Failed to set upstream repository: Read-only file system
Am I forced to use https or there's a way to configure it to work with ssh? my ssh key works fine in the terminal to push and it is in the normal location ~/.ssh

This answer possibly doesn't solve your issue but I'll still add it because this page was a first result in Google by "intellij settings repository auth fail" request.
I had an issue with "Auth fail" error when adding settings repository. I faced it after upgrade to macOS Mojave 10.14.1 which provides new version of ssh-keygen binary.
The cause was a new ssh key which I generated with ssh-keygen -t rsa -C "Michael Ledin" -b 4096 command.
Check your private SSH key (usually ~/.ssh/id_rsa). If it starts with
-----BEGIN OPENSSH PRIVATE KEY-----
then it has new RFC4716 key format which is currently not supported by JGit used by IntelliJ based IDEs.
To solve this issue you can:
either generate new key in old "PEM" format, add -m "PEM" option:
ssh-keygen -t rsa -C "Michael Ledin" -b 4096 -m "PEM"
or if you already added your public key to ssh remotes and repositories and it's hard to replace it with new key everywhere, then you have two options to convert it to old PEM format:
a) with ssh-keygen (it will ask for a new passphrase - use the old one or leave it empty):
ssh-keygen -p -m PEM -f ~/.ssh/id_rsa
b) with putty
first install putty and convert private key to SSH2 format (I presume that your current key is stored at ~/.ssh/id_rsa):
brew install putty
mv ~/.ssh/id_rsa ~/.ssh/id_openssh
puttygen ~/.ssh/id_openssh -O private-sshcom -o ~/.ssh/id_ssh2
next convert SSH2 key to PEM:
ssh-keygen -i -f ~/.ssh/id_ssh2 > ~/.ssh/id_rsa
rm ~/.ssh/id_ssh2
now you have your private key ~/.ssh/id_rsa in old PEM format that can be used by IntelliJ based IDEs; the original key is stored in ~/.ssh/id_openssh file and can be removed:
rm ~/.ssh/id_openssh
Links that were used to create this answer:
Convert OpenSSH private keys to RSA PEM
ssh-keygen does not create RSA private key

Does not and cannot work for certain SSH setups
The "Settings Repository" support for ssh is limited to the Java jgit implementation. Whereas you can configure new and existing projects to use your OS native ssh, this preference is ignored by the "Settings Repository" feature.
As such any jgit limitations which prevent it from working with your SSH setup will prevent the "Settings Repository" feature from working with no possible workaround.
Settings repository is a separate feature based on the JGit, and it is not related to the Version control - Git, that is why changing settings there has no effect.
Settings repository does not have a Native SSH mode and does not benefit from the ssh-agent.
Dmitriy Smirnov (JetBrains) — Settings Repository feature always asks for SSH key password even though key is in my SSH agent already
I downloaded and was in the process of setting up IntelliJ on a new machine when I ran into problems trying to overwrite my local settings from a settings repository. It seems like it is a problem with how Git is used internally by the settings repository. Below are examples of trying to use the Settings Repository feature and also Clone Repository with both Built-in and Native SSH. I'm not sure how to get this working correctly now.
Vladimir Krivosheev — Settings repository - add Native SSH mode (IDEA-173223)

Settings repository does work with the SSH keys.
Make sure you specify the URL correctly, as git#github.com:username/Repo.git
If your ssh keys are not called id_rsa/id_rsa.pub, make sure they are correctly referenced in the .ssh/config
Also, the error might occur because for some reasons IDE cannot overwrite local config files. Check the IDE logs for any related errors.

Related

Basic new dotty project instructions fail with "invalid privatekey", how to fix?

The getting started page for Dotty gives this instruction for starting a new project:
Create a Dotty project:
sbt new lampepfl/dotty.g8
When I run this, I get this error:
git#github.com:lampepfl/dotty.g8.git: invalid privatekey: [B#58aa5c94
It appears that possibly my authentication with GitHub is failing. Some googling led me to this answer which says it is due to using a newer OpenSSH id_rsa key.
So I created a new SSH key ~/.ssh/id_rsa.nonopenssh, added it to my SSH agent, and added it to my GitHub account, but I'm still getting the error. How do I fix this?
I think that merely adding the non-OpenSSH key is not good enough. For me I could only get it working once I'd removed the OpenSSH key from GitHub entirely. I also named the non-OpenSSH key ~/.ssh/id_rsa, which may not be necessary but it's what I did.
Summary:
(Might be optional) Rename your OpenSSH id_rsa keys: cd ~/.ssh && mv id_rsa id_rsa.bak && mv id_rsa.pub id_rsa.pub.bak
Generate a new RSA key: ssh-keygen -t rsa -m PEM
ssh-add -K ~/.ssh/id_rsa
Delete the old key from GitHub
Add the key to GitHub

Failed to add the SSH key to the ssh-agent with an empty passphrase (Bitrise CLI)

Summary:
As I'm integrating CI to the development workflow, I'm also trying to move the executions of Bitrise workflows to our local iOS Mac Computer which is setup as a Jenkins slave.
The projects that I'm trying to build therefore needs to be built on this iOS Computer.
Problem:
I'm trying to establish an ssh connection to an integration user (a GitHub account that has access to my repositories) and I have created a key and added it to the GitHub user as well as to the .bitrise.secrets.yml file.
But when the initial step, the activate-ssh-key step is executed, it results with an error that I can't add the SSH key to the ssh-agent with empty passphrase. (Is this somehow configurable? Can I just evade this?)
Here is the output log:
https://pastebin.com/FCHhZNDb
Step in bitrise.yml:
- activate-ssh-key#4.0.2: {getenv "SSH_RSA_PRIVATE_KEY"}
.bitrise.secrets.yml:
envs:
- SSH_RSA_PRIVATE_KEY: ssh-rsa *KEY*
|------------------------------------|
I have also tried putting the ssh key directly in the .ssh directory which did not work.
Any help is really appreciated! :)
TL;DR
Trying to connect bitrise cli with github via ssh, doesn't work.
The SSH key you used seem to be protected with a passphrase. You should generate one that does not require a passphrase to be specified, and register that for the repository.
How to generate such an SSH key: https://devcenter.bitrise.io/faq/how-to-generate-ssh-keypair/
ssh-keygen -t rsa -b 4096 -P '' -f ./bitrise-ssh -m PEM
Alternatively you can replace the Activate SSH Key step with a script one and activate the SSH key any way you like.
Or if you prefer to not to use SSH keys you could switch to using https:// git clone urls (instead of the SSH / git# one) and replace the Activate SSH Key step with the Authenticate with GitHub OAuth one (https://www.bitrise.io/integrations/steps/authenticate-with-github-oauth).

Error "The authenticity of host 'github.com' can't be established. RSA key fingerprint "

I use my project at work, but I would like to work with him from home as I can log into my home machine to work with my project.
However, from home, I see the following message:
The authenticity of host 'github.com (ip)' can't be established.
RSA key fingerprint is SHA256:nThbg6kXUpJWGl7E1IGOCspRomTxdCARLviKw6E5SY8.
Are you sure you want to continue connecting (yes/no)?
How can I get past it?
You should simply be able to answer 'yes', which will update your ~/.ssh/known_hosts file.
A better approach, to avoid any MITM (Man-In-The-Middle) attack, would be (as commented below by Mamsds) to verify Github's public key first (see "GitHub's SSH key fingerprints") and, if you find a match, then you can answer 'yes'.
Example:
ssh-keyscan -t ecdsa github.com 2>&1 |ssh-keygen -lf -
256 SHA256:p2QAMXNIC1TJYWeIOttrVc98/R1BUFWu3/LiyKgUfQM github.com (ECDSA)
After that, you can use a GitHub SSH URL (provided you have generated the SSH public/private keys, and registered the public one to your GitHub profile)
Note: the ssh key generation should use the base64 old PEM format (option -m PEM), rather than the new current 70 chars OpenSSH one.
See "What is the correct format for private key in Credentials":
ssh-keygen -m PEM -t rsa -P "" -f afile
That or you can switch to an HTTPS URL.
As you are attempting to connect to Github using SSH for the first time (no existing entry for Github in ~/.ssh/known_hosts yet), you are being asked to verify the key fingerprint of the remote host. Because, if an intruder host represents itself as a Github server, it's RSA fingerprint will be different from that of a GitHub server fingerprint.
You have two options.
You may just accept, considering you don't care about the authenticity of the remote host (Github in this case), or,
You may verify that you are actually getting connected to a Github server, by matching the RSA fingerprint you are presented to (in the prompt), with GitHub's SSH key fingerprints in base64 format.
The latter option is usually more preferable.
Just add Github fingerprint to known hosts this way:
mkdir -p ~/.ssh
ssh-keyscan -t rsa github.com >> ~/.ssh/known_hosts
Use one of the following two solutions:
1) Set up the SSH key
Follow the steps discussed on this GitHub help page.
https://help.github.com/en/github/authenticating-to-github/connecting-to-github-with-ssh
2) Clone using git with HTTPS
Type (copy/paste) the following commands in a terminal on the machine where you would like to clone the repository
git config --global url."https://github.com/".insteadOf git#github.com:
git config --global url."https://".insteadOf git://
You can revert this change using the following commands
git config --global url."git#github.com:".insteadOf https://github.com/
git config --global url."git://".insteadOf https://
Try these steps:
Open Git Bash
Check for existing SSH keys:
$ ls -al ~/.ssh
If you already have them, you will see:
id_rsa.pub
id_ecdsa.pub
id_ed25519.pub
If you don't, generate one (Press Enter to accept the default file location):
$ ssh-keygen -t rsa -b 4096 -C "your_email#example.com"
To copy the key to clipboard:
$ clip < ~/.ssh/id_rsa.pub
Go to your account on Github/Settings/SSH and GPG keys/New SSH key
Paste your key there
Next, type:
$ git remote
If you see origin, remove it:
$ git remote remove origin
Continue with the last 2 steps provided on GitHub repo page...
$ git remote add origin git#github.com:USERNAME/REPONAME.git
$ git push -u origin master
Refresh your GitHub repo page
Voila!
1- Create SSH key
if you don't have the ssh-key create it like this:
ssh-keygen -t rsa -b 4096 -C "youremail#example.com"
2- Check your SSH key
For this go to your folder ssh, example:
cd ~/.ssh
after that, run this command line : ls
if you have the files: id_rsa, id_rsa.pub so the all is good
now you need to copy your id_rsa.pub ! (⚠️ NOT the id_rsa)
for this run cat id_rsa.pub and copy the result
3- Github / Gitlab
Go to your github / gitlab.
Follow the step by your hosting:
github: Click on your profile -> Settings -> SSH and GPG Keys -> New SSH key
gitlab: Click on your profile -> preferences -> SSH keys
past your id_rsa.pub that you have already copied !
4- If you have already did it and it's already not working ??
When your enter your ssh-key in github / gitlab your key have a Expiration date so you just need to change it
That it ! Have a good work 😀
You just need to type yes and it will work, for more information you can refer to the Official Github documentation. This will give an output saying
Hi <username>! You've successfully authenticated, but GitHub does not provide shell access.

Gitkraken cannot use local SSH agent

I have recently changed my GitHub username and when I try to push with Authentication > Use local SSH agent selected, GitKraken push fails with following error:
Push Failed
Configured SSH key is invalid.
Please confirm that it is properly associated with your git provider.
Unselecting the option reveals proper private/public key pair located at
~/.ssh/id_rsa
~/.ssh/id_rsa.pub
and allows the push to be done.
I can also push from inside Eclipse, and via command line without error. The URL of the repository point to my new username.
So far I have checked several things:
ssh -T github.com
gives permission denied
Fingerprint of id_rsa.pub matches to a key existing in Github account.
The following command suggests that ssh tool tries rsa private key, but is rejected:
$ ssh -vT github.com
debug1: Offering RSA public key: /home/<user>/.ssh/id_rsa
debug1: Authentications that can continue: publickey
debug1: Trying private key: /home/<user>/.ssh/id_dsa
debug1: Trying private key: /home/<user>/.ssh/id_ecdsa
debug1: Trying private key: /home/<user>/.ssh/id_ed25519
debug1: No more authentication methods to try.
Permission denied (publickey).
What is causing ssh -vT to fail in this case, and why doesn't it prevent git push/pull but fails when GitKraken tries pushing?
For me this was caused by an upgrade to OSX Sierra. I had to execute
ssh-add -k ~/.ssh/id_rsa
(you might have to replace that with the path of the key you are using). The command adds the ssh key to the git agent. For more information see the GitHub Help Page about adding SSH Keys.
You might have to add the command to some sort of setup file which is run at boot, because it seems like the ssh agent doesn't remember the key (at least for me).
For people who will come here in the future, my case was that pull/push working on vsc but gitkraken was giving me the message : no auth sock variable.
I went into file > preferences > SSH > unmarked use local SSH agent then it automatically found my id_rsa, ida_rsa.pub (you can browse and locate them manually if needed)
and now everything working fine.
OS: Arch,
gitkraken version: 7.7.2
What helped me resolve the issue was to go to GitKraken preferences and connect both Bitbucket and Github and authorize them.
After that tick the box in "general" that says use local ssh agent. (might be
If you have already set-up your local SSH agent, and your Git in terminal works, but Gitkraken does not, this might help:
First, start gitkraken from your terminal, instead of a desktop shortcut:
Open your favorite terminal
Run gitkraken
See if "Pull" works, or any other authenticated operation
It it works, you need to edit your Gitkraken desktop shortcut:
In my scenario, this is where my desktop shortcut is located, so: sudo vim /usr/share/applications/GitKraken.desktop
Change Exec=gitkraken %f to Exec=env SSH_AUTH_SOCK="${XDG_RUNTIME_DIR}/ssh-agent.socket" gitkraken %f

How to use multiple Git SSH keys on Eclipse?

I looked several answers and forums for a solution but I could not find a single one that works.
I have this scenario:
Eclipse Luna Service Release 2 (4.4.2)
Ubuntu 14.04 x64
Two ssh keys on my ~/.ssh folder
Two bitbucket accounts (one for personal projects and one for enterprise)
A git repository only accessible with my primary key (~/.ssh/id_rsa)
A git repository only accessible with my secondary key (~/.ssh/other)
I created a ~/.ssh/config file with the contents:
Host bitbucket bitbucket.org
Hostname bitbucket.org
IdentityFile ~/.ssh/id_rsa
IdentityFile ~/.ssh/other
User git
And for the sake of sanity I added the second key using ssh-add as well. Running ssh-add -l lists both keys.
When using the command line, all git commands work like a charm, with both repositories. But when using Eclipse, I always get the Invalid remote: origin error when trying to clone or pull from the repository with the secondary key:
Caused by: org.eclipse.jgit.errors.NoRemoteRepositoryException: git#bitbucket.org:myuser/myrepository.git: conq: repository access denied.
I added the secondary key at Window > Preferences > Network Connections > SSH2 > Private keys, and set the GIT_SSH environment variable to point to my ssh executable:
$echo $GIT_SSH
/usr/bin/ssh
I've restarted Eclipse and even the OS several times, with no luck.
Since I can use git from the command line without problems, I tend to believe there's something wrong with Eclipse.
How to use multiple Git SSH keys on Eclipse? Or how to force Eclipse to use my secondary key on a single project?
Host bitbucket bitbucket.org? You don't declare multiple entry names on one Host section.
I would expect to see in a ssh config file declaring multiple keys:
Host bitbucketuserA
Hostname bitbucket.org
IdentityFile ~/.ssh/id_rsa
User git
Host bitbucketuserB
Hostname bitbucket.org
IdentityFile ~/.ssh/other
User git
And you would use ssh url like
bitbucketuserA:userA/myrepo1
bitbucketuserB:userB/myrepo2
(this is similar to what I suggested for "How to work on personal GitHub repo from office computer whose SSH key is already added to a work related GitHub account?")