How to add ssh key in git bash? - ssh

To add key in Gitbash Make sure to use to enable ssh agent first.
eval $(ssh-agent -s)
[enter image description here][1]
Now you can add ssh key in git bash using below command.
if you are doing it in windows Git Bash.
ssh-add /c/keyname
How to check if the key is added.
ssh-add -L
you should see the ssh key added here .

Below are the steps:
Open Git Bash and run below command on command prompt to generate public-private key pair ssh-keygen -t rsa -b 4096 -C "your_email#gmail.com"
When you are prompted to "Enter a file in which to save the key," press Enter. This accepts the default file location.
Enter a file in which to save the key (/c/Users/username/.ssh/id_rsa):[Press enter]
At the prompt, type a secure passphrase. You can press enter if you want to leave it blank but its not recommended.
Enter passphrase (empty for no passphrase): [Type a passphrase]
Enter same passphrase again: [Type passphrase again]
Go to /c/Users/username/.ssh/ folder and open id_rsa.pub file and copy entire contents of it.
Finally, go to Github -> Settings -> SSH And GPG keys -> Click New RSA (Green Button). Give some meaningful title to the key and paste the public key copied in step 4 above. Now click on Add SSH Key button.
Congrats, you have added public key to github successfully and now you can use gitbash to access github repositories.

Usually, I take a look from git GUI (in Windows). There is a menu about SSL (or SSH) and you can view the imported key.

Related

Cannot copy ssh key after generation

So I created a ssh key and can find the folder but on trying to copy,it won't work.Keeps telling me the system cannot find the path specified
My command prompt is on Windows,
Command
Clip <clip ~/.ssh/id_rsa.pub

Git saves SSH in local project repository not in C:\Users\user-name/.ssh/id_rsa

I added a ssh key.
ssh-keygen -t rsa -b 4096 -C "my email"
Generating public/private rsa key pair.
Enter file in which to save the key (C:\Users\user-name/.ssh/id_rsa):testkey
Enter passphrase (empty for no passphrase):
Enter same passphrase again:
Your identification has been saved in testkey.
Your public key has been saved in testkey.pub.
I tried commands like ls -al ~/.ssh and cat ~/.ssh/id_rsa.pub to find it. Didn't help.
Than i created a .ssh folder in my user directory using mkdir ${HOME}/.ssh and tied to create another SSH key. I did it in VS Code so it told me
testkey already exists.
Overwrite (y/n)?
Then i decided to cat testkey.pub and it returned me a key. Than i checked my local repo and found 2 files testkey and testkey.pub
So why it can't save in C:\Users\user-name/.ssh/id_rsa ?
I obviously don't want to store it my local project repo
I am still learning. Was watching Course about Git but got stuck on 22:00 with this problem
Enter file in which to save the key (C:\Users\user-name/.ssh/id_rsa):testkey
You entered filename without full path so ssh-keygen saves the keypair in the current directory. The answer should be
Enter file in which to save the key (C:\Users\user-name/.ssh/id_rsa):C:\Users\user-name/.ssh/testkey
Or
C:
cd \Users\user-name\.ssh
ssh-keygen
Enter file in which to save the key (C:\Users\user-name/.ssh/id_rsa):testkey

I'm trying to create a new repository on github but can't get my ssh key

I cant make a repository because I don't have an ssh key on git hub but I don't know how to get that I fallowed a video and it was going good until he copy pasted it and that won't work for me. I tried clip < ~/.ssh/id_rsa.pub
but when I hit CTRL V nothing pastes.
In your terminal:
sudo apt-get install xclip
Then:
xclip -sel clip < ~/.ssh/id_rsa.pub
Key should be in your clipboard now.
Log-in to Github > Click on your profile photo > Click Settings > Click on SSH and GPG in your sidebar > Click New SSH key or Add SSH key > Enter a title like "My Linux machine" > Paste your key into the Key field.
Done.

How do I add an SSH key in gitlab?

Here is what my dashboard looks like:
Not really sure where to add an SSH key. Anyone have any idea?
You need to sign in. Green button top right.
Click 'profile settings' on the left side menu.
Click SSH Keys and follow the instructions on the page.
Go to your GitLab account: https://gitlab.com/
Click on Settings on the top right drop-down, which will appear once you select the icon(white-fox image [specific to my profile]).
Click on Settings on the top right drop-down, which will appear once you select the icon(white-fox image).
Click on SSH Keys:
Add/Paste the SSH Key.
How to generate the ssh key: Download gitbash or putty:
After downloading gitbash/putty follow the steps:
Open a terminal on Linux or macOS, or Git Bash / WSL on Windows.
Generate a new ED25519 SSH key pair:
ssh-keygen -t ed25519 -C "email#example.com"
Or, if you want to use RSA:
ssh-keygen -t rsa -b 4096 -C "email#example.com"
It will generate the key in => C:\Users\yourname.ssh directory.
Copy the public key and paste in the gitlab location:
Command to run on gitbash to clone the repository:
ssh-agent $(ssh-add C:\Users\youname\.ssh\id_rsa; git clone git#gitlab.com:xyz/SpringBootStarter.git)
Just follow the official guides to Create and Add SSH keys.
Goto https://gitlab.com/profile/keys.
If you are a new user a banner will show at the top of each project page.
You won't be able to pull or push project code via SSH until you add
an SSH key to your profile
However, you can dismiss this warning.
First, you need to do open terminal after that type
mkdir -p ~/.ssh
echo public_key_string >> ~/.ssh/authorized_keys
chmod -R go= ~/.ssh
chown -R shabeer:shabeer ~/.ssh
ssh-keygen or ssh-keygen -t ed25519 -C "mail#example.com"
xclip -sel clip < ~/.ssh/id_ed25519.pub
~/.ssh/gitlab_rsa.pub
in this time can see your key and copy it, After that Go to the Gitlab settings and chose SSH Keys, you can see there have to option add that copied key

How to create GPG keys via shell script for root user?

For an application I'm making I have to use GPG in a root process on machine #1. On some other machine (#2) I want to run a shell script, that creates keys (secret and public) in GPG for user root on machine #1.
First I create a file, key.scr, where I define characteristics for the new key.
When I run
gpg --batch --gen-key /hdd/myfolder/key.scr"
via ssh for user , a perfect key-pair is created and saved in /home//.gnupg
But my goal is to create keys for the user root, who must use these keys in some crontab-job.
I tried the following:
echo "<MyPassword>" | sudo -S gpg --batch --gen-key /hdd/myfolder/key.scr
and
sudo -u root gpg --batch --gen-key /hdd/myfolder/key.scr
I also placed
gpg --batch --gen-key /hdd/myfolder/key.scr
in a shell command file , and ran
sudo <BatchFile>
but I only messed up the .gnupg folder for (the access rights for several files in this folder are changed to root - root, so they are not readable any longer by .
So, what is the proper way to create via ssh GPG keys which can be used by user root, while root access is not possible via ssh?