How to add a passphrase for ssh key after its been created? - github

Is generating a new one necessary, or is there a way to go back and add a passphrase?
I have generated an ssh key, but would like to go back and add a passphrase. I haven't linked it to my github yet. Is there any way to do this?

As explained here, you can add a passphrase to an existing private key with:
cd ~/.ssh
ssh-keygen -o -p -f keyfile
But you can also link that to GitHub immediately: adding a passphrase (encrypting the private key) does not change the public key you would register to your GitHub profile.
The public key will remain the same, before and after you add a passphrase to your local private key.

Related

GitHub : import SSH i cant import ssh key in my github account

when i want to import my ssh key in github i have This Erorr "Key is invalid. You must supply a key in OpenSSH public key format"
Try again with:
ssh -P "" -t rsa -f ~/.ssh/github
cat ~/.ssh/github.pub
Copy the public key content in your GitHub SSH setting page: this one should work.
One starting with SHA256:... looks like a key fingerprint, not an actual public key.

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

How do I know which ssh key is used in my github account?

When I go to the SSH keys page in my GitHub account, I see a key whose identity starts with "c5:42:08:9d:39:22..."
On my computer, in the ".ssh" folder, I have several files that look like public SSH keys, but none of them contains a string similar to the above. For example, one
of the files "id_rsa.pub" contains a string that starts with "ssh-rsa AAAAB3NzaC1yc2EAAAADAQABA..." there are other similar files that probably represent different keys.
How can I identify which of the files, if any, represents the actual key that is in my github account?
"c5:42:08:9d:39:22..." isn't the key, but rather the key's fingerprint. You can see your key's fingerprint using ssh-keygen:
ssh-keygen -lf ~/.ssh/id_rsa
Where
-l means we want to see the key's fingerprint
-f ~/.ssh/id_rsa is a path to the key whose fingerprint we want to see
On older versions of OpenSSH, you may need to also specify that you want the SHA256 fingerprint rather than another hash like MD5, since SHA256 is what GitHub shows in its web interface:
ssh-keygen -lf ~/.ssh/id_rsa -E sha256
You should get the same fingerprint from the public part as from the private part of the keypair.

Add SSH key for both github and bitbucket in single PC

Is it possible to use both the github and bitbucket repo in personal computer.
if not, Let me know any other possibilities.
Thanks in advance.
Complete Guide to Add SSH keys for both github and bitbucket in single PC
if you already have one ssh key then you must have 2 files public(id_rsa.pub) and Private key(id_rsa) in the .ssh folder You can Skip the Step 2
Step 1. Prepare your default identity it Required for Both Account Before Doing Step 2 and Step 3
Determine your Git clone URL.
$ git remote -v
origin git#bitbucket.org:teamsinspace/bitbucketspacestation.git (fetch)
origin git#bitbucket.org:teamsinspace/bitbucketspacestation.git (push)
Update the remote URL with your Bitbucket username by replacing git#bitbucket.org with <username>#bitbucket.org.
For this step and the ones that follow, enter your username in place of .
$ git remote set-url origin <username>#bitbucket.org:teamsinspace/bitbucketspacestation.git
Step 2 : create the 1st ssh key with default names (id_rsa)
$ssh-keygen
You will see the following text:
Generating public/private RSA key pair.
Enter file in which to save the key (/home/username/.ssh/id_rsa):
you can input the password to secure your file or you can press enter for all the steps and then it will create one ssh key.
By default, the system adds keys for all identities to the /Users/<username>/.ssh directory
You can check the already existing ssh key by following command
$ ls ~/.ssh
id_rsa id_rsa.pub
Two files should be there one with the name of the key(id_rsa) Private key second with the same (ir_rsa.pub) public key.
you can open make it visible by ctrl + h in Home Directory
then it will be shown
Second, Create your known hosts file if you not have already
To create your known hosts files-
touch known_hosts
STEP 3 : Sethup the Multiple account ssh
3.1 : Create 2nd Key With default name
You might be using one SSH key pair for working on your company's internal projects, now but you might be need a diffrent key for accessing a client's servers so you can create the key
By run the same command ssh-keygen again it will create the 2nd ssh key files with the name of [ id_rsa2 and id_rsa2.pub ]
3.2 : Create the 2nd Key with Custom Name
ssh-keygen -f NAME_OF_YOUR_KEY
$ ssh-keygen -f work_key it will create then 2 files
[ work_key, work_key.pub ]
if want to run the one key at a time then you can use this command before connecting to that repo for pull and push .
ssh-add -K ~/.ssh/YOUR_KEY_FILE
ssh-add -K ~/.ssh/work_key
Step 4 : Setup both two Accounts at the same time
You want to Setup both two Accounts at the same time then you will have to use the following command
Third Create your config file
To create your config file
touch config or open directly into any text editor,
Here is Example for One Github and one Bitbucket account
Host : name of your ssh setting you can give custom name
HostName : github domain or bitbucket domain
IdentityFile : path of your ssh file
#Work account
Host pers
HostName github.com
User git
IdentityFile ~/.ssh/id_rsa
UserKnownHostsFile ~/.ssh/known_hosts
IdentitiesOnly yes
#Personal account
Host work
HostName bitbucket.org
User git
IdentityFile ~/.ssh/work_key
UserKnownHostsFile ~/.ssh/known_hosts
IdentitiesOnly yes
Step 5 : Add your public keys to the Bitbucket or github account
For Bitbucket
For Github [Go to Setting of your Account -> SSH and GPG key]
Step 6 : Add your public permanently
ssh HOST(What we written in config file )
like
ssh work
if you got this error make sure you did Step 4 Correctly.
git#bitbucket.org: Permission denied (publickey).
or can be use this way as well
Now you can use
git clone `git#pers/project.git`
git clone `git#work/project.git`
Step 7 : auotmaticly pick by domain name we are requiesting to
Managing SSH keys can become cumbersome as soon as you need to use a second key. Traditionally, you would use ssh-add to store your keys to ssh-agent, typing in the password for each key. The problem is that you would need to do this every time you restart your computer, which can quickly become tedious.
if you have only two account and one in the github and one in the bitbucket you can use the following approch to auotmaticly pick by domain name we are requiesting to
#Work account
Host github.com
HostName github.com
User git
IdentityFile ~/.ssh/id_rsa
UserKnownHostsFile ~/.ssh/known_hosts
IdentitiesOnly yes
#Personal account
Host bitbucket.org
HostName bitbucket.org
User git
IdentityFile ~/.ssh/work_key
UserKnownHostsFile ~/.ssh/known_hosts
IdentitiesOnly yes
Here is a link to further guidance on it
https://www.freecodecamp.org/news/the-ultimate-guide-to-ssh-setting-up-ssh-keys/
https://support.atlassian.com/bitbucket-cloud/docs/set-up-additional-ssh-keys/
Yes it is. You tell git where the remote code lives from a per-repository configuration file. You can even push to GitHub and Bitbucket from the same repository if you want to.
See here for more details:
http://blog.lckymn.com/2013/03/11/git-push-to-pull-from-both-github-and-bitbucket/
One important piece will be connecting to each separately with SSH.
Your SSH keys should live in $HOME/.ssh and can contain any number of keys. The default name for an SSH key is id_rsa (or similar, depending on the protocol used to create it).
Try doing:
ls $HOME/.ssh
... to see what's in there.
I do what you are asking about myself and for me that brings up something like:
github-personal
github-personal.pub
bitbucket-work
bitbucket-work.pub
known_hosts
Where known_hosts is a file that contains a list of the servers I connect to and the public keys associated with them. The other files that end in .pub are my own public keys and the rest are my private keys.
You get your GitHub and Bitbucket keys into there by following their appropriate tutorials:
GitHub: https://help.github.com/articles/generating-ssh-keys/
Bitbucket: https://confluence.atlassian.com/display/BITBUCKET/Set+up+SSH+for+Git
Yes, it is possible to use both the github and bitbucket repo in personal computer.
You can setup multiple SSH profiles.
First Generate your SSH keys To generate the first key-from your root folder
$ cd ~/.ssh
$ ssh-keygen -f work_key,
then enter a passphrase of your choice.
To generate the second key
$ ssh-keygen -f personal_key, then enter a passphrase of your choice.
Second, Create your known hosts file
To create your known hosts files-
touch known_hosts
Third Create your config file
To create your config file
touch config, then it would look something like this
#Work account
Host bitbucket.org
HostName bitbucket.org
User git
IdentityFile ~/.ssh/id_rsa
UserKnownHostsFile ~/.ssh/known_hosts
IdentitiesOnly yes
#Personal account
Host bitbucket.org
HostName bitbucket.org
User git
IdentityFile ~/.ssh/id_rsa2
UserKnownHostsFile ~/.ssh/known_hosts
IdentitiesOnly yes
Then add your SSH key to bitbucket. Go to bitbucket, settings, then SSH keys
pbcopy < id_rsa.pub (to copy the key) and paste it in bitbucket
Definitely YES. You can generate ssh key pair first, see How to generate, then go to .ssh directory, copy the content of id_rsa.pub, and paste into your github or bitbucket ssh setting area.
I make use of Sourcefree Desktop Application and My Gitbash prompt
to push my project to Bitbucket and Github repository simultaneously
below is what i did
right click to open bash shell of the folder you want to push
First you need to create key, i will advice make use of the same ssh key
create key
ssh-keygen -t rsa -C "your_email#example.com"
go to the folder directory
right click and click on git bash
then run the below command one after the other
git init
git add .
git commit -m "first"
open your sourcefree desktop app
click on + to open your local
repo file
create repo on bitbucket
then click repo icon
then click on repo icon to add
name: originbit
url: "repo link you created"
For your bitbucket you have to make use of both
public ssh key and private ssh key if you want to make use of
both public and private repository
To make use of ssh key earlier created
go to TOOLS icon of sourcefree App
Click on load tab
then resave it with .ppk extension
save the same key as private key and public key
in the same directory
dont input passhrase yet to avoid difficulties
just save it.
so that it can be loaded to pageant icon
to create new key
go to TOOLS icon of sourcefree
then click on create ssh key
change the bottom number to 2048
but if you are unable to change it
first create a new key then drag your mouse around the colum provided
in a zigzag way or any form once created.
change the 1048 to 2048 so that it can be accepted at bitbucket ssh
then recreate a new key
then save it as public key and private key
add key to the Pageant (check your desktop notification for this Pageant key icon)
add both private ssh key and ssh public key
Goto your bitbucket account seetings
and add the content of the two ssh keys
name them differently
go back to the bash shell
git status
git add -A
git pull originbit master
git commit -m "modified code"
git push originbit master
create repo on github
Open Sourcefree desktop app
copy the repo url
then click repo icon
then click on repo icon to add
then push on Sourcefree

Why do I need to run `ssh-add` in my Powershell profile?

In my Microsoft.PowerShell_profile.ps1 document, I've had to add ssh-add ~/.ssh/github_rsa following the poshgit examples in order for it to connect to my GitHub repos.
# Load posh-git example profile
. 'C:\tools\poshgit\dahlbyk-posh-git-8aecd99\profile.example.ps1'
ssh-add ~/.ssh/github_rsa
If I don't have that in my profile, I Github gives me permissions errors when I try to connect.
If I do it manually, it will work for the entire duration of my desktop session, but as soon as I reboot my computer, I need to re-run the command.
Why doesn't poshgit and ssh-add remember the rsa that I've added? It seems wrong to have to re-add it every time.
It's because your rsa key is not the default name ( id_rsa ) so you either need to use ssh-add (which adds it to a running service that remembers the key decrypted with your passphrase) or just add an entry into your ~\.shh\config
~\.ssh\config (create or edit):
Host github.com
HostName github.com
User git
IdentityFile ~/.ssh/github_rsa
Or, if github is the only thing you use ssh keys for, just rename the key to id_rsa and then git (well ssh.exe) will find it for you automatically AND poshgit will ssh-add it for you (to handle passphrases).