'How to generate ssh keys (for github)
Question: How do I generate ssh private and public keys (to be used in GitHub/GitLab) using command line.
The command below generates the error
sh.exe": syntax error near unexpected token '('
I am using Windows XP.
$ ssh-keygen -t rsa -C "[email protected]"
Generating public/private rsa key pair.
Enter file in which to save the key (/c/Users/xxxx/.ssh/id_rsa):
Enter passphrase (empty for no passphrase):
Enter same passphrase again:
Your identification has been saved in /c/Users/xxxx/.ssh/id_rsa.
Your public key has been saved in /c/Users/xxxx/.ssh/id_rsa.pub.
The key fingerprint is:
01:0f:f4:3b:ca:85:d6:17:a1:7d:f0:68:9d:f0:a2:db [email protected]
Solution 1:[1]
The command to run is only
ssh-keygen -t rsa -C "[email protected]"
All the rest beginning with line 2 of your script is the output of ssh-keygen.
And replace [email protected] with your email address.
Have a look at the manual for ssh-keygen
to look for additional options. You should probably use a longer key by adding -b 4096
to the option list.
Solution 2:[2]
Here is the command
ssh-keygen -t rsa -b 4096 -C "[your github's email]"
# Creates a new ssh key
# Generating public/private rsa key pair.
This will generate a key for you. You have to copy that and insert into your Github's account (just one time).
Solution 3:[3]
Step 1: Generate Your SSH Key
$ ssh-keygen -t rsa -b 4096 -C "[email protected]"
Step 2: Use the Key
$ eval $(ssh-agent -s)
Then add the key we just generated. If you selected a different path than the default, be sure to replace that path in the command.
ssh-add ~/.ssh/id_rsa
Step 3: Add the SSH Key on GitHub
clip < ~/.ssh/id_rsa.pub
if clip not found then add the next command
cat ~/.ssh/id_rsa.pub
Finally Result something like on your cmd
ssh-rsa AAAAB3NzaC1yc2EAAAAD173Oe1kp0Ojnsn7sRWt/XT5nFH3CSTv6VWyxq4YUJ4ZykWa5opyiAJmvtjxOMCmVTuX2r1T4Livn0foHGt7+66FJXrXUQgyJ4RXanufb3bAekxbFPg3S6Gyr2kk+I3TYWcFsLLwjU0VVJwodQkpyygAUzhomx9OQ0FMpfkQa5VrZnaSLjjtNOUSAaq30e7JWYxtoVih2HfVkcmqc53QjY4T3Xb0cmLZF3EmwCeB66dgJtpTNMvM54ceD30INsaMFNqG8XjbJtGUCHYEIR5l/LI20K5F25BRTnCzRV9dB5FUJ8taVMGRHJob9PDUdxpA2HEJYilm8ZbLbRmKJtU+H91WNCG6pvy9Yf9MREkOZQHcWIuAsH8uJvTTbqm1eAY2g34FjarRdqZIpvdxkrErDHqh4k42owNEmHjSaAw53Y8M54fjBdFHTjGDqHBamlKcIzQbin/czFq1a+pgopIANDhZjWZNvMiTak7BjVrVOciKD3Pa/KKy03nSEfEGExLbFEi1Q8QEGd6idtUAjL7fyVPWatRwCnOvGLMPTk73m7t0IAYTm4n7dO0S5OeWTUPTT+8vIfFCmE9OT2aJDIpZY1+f8Q== [email protected]
copy from your cmd and go to your GitHub account setting find ssh and gpg keys
Solution 4:[4]
Solution: ssh-keygen -t rsa
Explanation : ssh-keygen
is a tool for creating new authentication key pairs for SSH. Such key pairs are used for automating logins, single sign-on, and for authenticating hosts
(for example cloning project from your private repo on Github straight to your aws machine).
Options: You can perform more complicated operations and using flags in order to generate a tailor-made key according to your use case, extended functionality are more powerful and secured. The basic flags are: bits
(Large integers making the the RSA key be less vulnerable and hard to crack), passphrase
(similar to password) , type
(dsa/ecdsa/ed25519/rsa) , comment
for the specific ssh token (email or user name) and output key
(default store on ~/.ssh/ path)
Synopsis: ssh-keygen [-q] [-b bits] [-t dsa | ecdsa | ed25519 | rsa] [-N new_passphrase] [-C comment] [-f output_keyfile]
Example:
ssh-keygen -b 4096 -t rsa -n "tHiSiaPasSWoRd" -c "[email protected]" -f ~/.ssh/id_rsa
Solution 5:[5]
Generate SSH key using below command
ssh-keygen -trsa -C [email protected]
just hit enter to apply the default value for all the inputs it asks
the output will be
Generating public/private rsa key pair.
Enter file in which to save the key (/home/user/.ssh/id_rsa):
/home/user/.ssh/id_rsa already exists.
Overwrite (y/n)? y
Enter passphrase (empty for no passphrase):
Enter same passphrase again:
Your identification has been saved in /home/user/.ssh/id_rsa
Your public key has been saved in /home/user/.ssh/id_rsa.pub
The key fingerprint is:
SHA256:xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx [email protected]
The key's randomart image is:
+---[RSA xxxx]----+
| ..++xX*Ox |
| x..xx/+.x. + . |
|.. +..*+xx x + |
|... +x+o x. |
|x.. + +..x |
|xx.. x |
|... |
|x x |
|x x. |
+----[SHA256]------+
just use the cat
command to log the ssh key file contents on the terminal(use your own path here).
cat /home/user/.ssh/id_rsa.pub
the output will be
ssh-rsa xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx [email protected]
copy the contents and go to your github account go to settings under Account settings>SSH and GPG keys click on New SSH key
, provide the name you wish and paste the copied contents in the value and save. that's it you are ready to commit your changes without using username, password every time.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|---|
Solution 1 | |
Solution 2 | Muhammad Dyas Yaskur |
Solution 3 | Naved Khan |
Solution 4 | avivamg |
Solution 5 | Akhil S |