How do I access my SSH public key?
Solution 1
cat ~/.ssh/id_rsa.pub
or cat ~/.ssh/id_dsa.pub
You can list all the public keys you have by doing:
$ ls ~/.ssh/*.pub
Solution 2
Copy the key to your clipboard.
$ pbcopy < ~/.ssh/id_rsa.pub
# Copies the contents of the id_rsa.pub file to your clipboard
Warning: it's important to copy the key exactly without adding newlines or whitespace. Thankfully the pbcopy command makes it easy to perform this setup perfectly.
and paste it wherever you need.
More details on the process, check: Generating SSH Keys.
Solution 3
You may try to run the following command to show your RSA fingerprint:
ssh-agent sh -c 'ssh-add; ssh-add -l'
or public key:
ssh-agent sh -c 'ssh-add; ssh-add -L'
If you've the message: 'The agent has no identities.', then you've to generate your RSA key by ssh-keygen
first.
Solution 4
If you're on Windows use the following, select all, and copy from a Notepad window:
notepad ~/.ssh/id_rsa.pub
If you're on OS X, use:
pbcopy < ~/.ssh/id_rsa.pub
Solution 5
Mac, Ubuntu, Linux compatible machines, use this command to print public key, then copy it:
$ cat ~/.ssh/id_rsa.pub
sscirrus
Updated on July 24, 2022Comments
-
sscirrus almost 2 years
I've just generated my RSA key pair, and I wanted to add that key to GitHub.
I tried
cd id_rsa.pub
andid_rsa.pub
, but no luck. How can I access my SSH public key? -
sscirrus over 13 yearsEven though I see the file in the place it's referring to (C:/Users/Me/.ssh/.id_rsa.pub), these commands are producing an error: No such file or directory. I'm doing this from Git Bash, MyPC ~/.ssh
-
Peter Štibraný over 13 years@sscirrus: In windows, you can use
type
command. Or just open the .pub file in notepad and paste it to github. -
sscirrus over 13 yearsThanks a lot Peter, for the answer and the edit. Make it an answer and I'll accept :)
-
Peter Štibraný over 13 years@sscirrus: accept this one ... it works as well (under unix or cygwin)
-
karlingen about 10 yearson Mac OS X:
cat ~/.ssh/id_rsa.pub
-
laggingreflex almost 10 yearsOn Windows too, it's just
id_rsa.pub
, not *.
*id_rsa.pub
-
Mitch Dempsey almost 10 years@laggingreflex I've updated the answer to be clearer
-
iamprem about 9 yearsWhen i do so, its opening a blank file. Its not showing any text in it. But when i browse through file manager, i'm able to see the text.
-
bigbiggerpepe almost 8 years
sudo apt-get install xclip -y
for those users who doesn't havepbcopy
working. -
Jun711 about 6 yearsOn a Mac, you can do this to copy it to your clipboard (like cmd + c so that you can cmd + v to paste) cat ~/Desktop/ded.html | pbcopy pbcopy < ~/.ssh/id_rsa.pub
-
Eduard over 5 years
$
in$ ls ~/.ssh/*.pub
was not required on my Mac. -
gebbissimo about 5 years
sudo apt-get install -y xclip
followed byalias pbcopy="xclip -sel clip"
and thenpbcopy < ~/.ssh/id_rsa.pub
OR simplyxclip -selection clipboard < ~/.ssh/id_rsa.pub
-
rudolfbyker almost 5 yearsThis is good for when you don't know the path of the key beforehand. It's not always in
~/.ssh/
. -
iamkeir over 4 yearsThis is my favourite way.
-
Filip Haglund about 4 yearsTried it out, works on Mac, Win10 (in git bash) and Ubuntu.
-
steinybot about 4 yearsUsing
ssh-add -L
is by far the better option as not every SSH key is an RSA key sitting in the~/.ssh
folder. I much prefer to use my PGP key for authentication and so I do not have a~/.ssh/id_rsa.pub
file at all. -
dvdmn almost 4 yearseven though I cannot find the file on terminal or finder, opening the file with text editor works... thanks
-
Sharpey over 3 yearsif
ls ~/.ssh/*.pub
display nothing you need to generate your public key first. This was my issue on new machine. -
Parthi over 2 yearsGenerate one if ssh key is not there already. As mentioned in one of the response.