How do I access my SSH public key?

1,361,481

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
Share:
1,361,481
sscirrus
Author by

sscirrus

Updated on July 24, 2022

Comments

  • sscirrus
    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 and id_rsa.pub, but no luck. How can I access my SSH public key?

  • sscirrus
    sscirrus over 13 years
    Even 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ý
    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
    sscirrus over 13 years
    Thanks a lot Peter, for the answer and the edit. Make it an answer and I'll accept :)
  • Peter Štibraný
    Peter Štibraný over 13 years
    @sscirrus: accept this one ... it works as well (under unix or cygwin)
  • karlingen
    karlingen about 10 years
    on Mac OS X: cat ~/.ssh/id_rsa.pub
  • laggingreflex
    laggingreflex almost 10 years
    On Windows too, it's just id_rsa.pub, not *.*id_rsa.pub
  • Mitch Dempsey
    Mitch Dempsey almost 10 years
    @laggingreflex I've updated the answer to be clearer
  • iamprem
    iamprem about 9 years
    When 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
    bigbiggerpepe almost 8 years
    sudo apt-get install xclip -y for those users who doesn't have pbcopy working.
  • Jun711
    Jun711 about 6 years
    On 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
    Eduard over 5 years
    $ in $ ls ~/.ssh/*.pub was not required on my Mac.
  • gebbissimo
    gebbissimo about 5 years
    sudo apt-get install -y xclip followed by alias pbcopy="xclip -sel clip" and then pbcopy < ~/.ssh/id_rsa.pub OR simply xclip -selection clipboard < ~/.ssh/id_rsa.pub
  • rudolfbyker
    rudolfbyker almost 5 years
    This is good for when you don't know the path of the key beforehand. It's not always in ~/.ssh/.
  • iamkeir
    iamkeir over 4 years
    This is my favourite way.
  • Filip Haglund
    Filip Haglund about 4 years
    Tried it out, works on Mac, Win10 (in git bash) and Ubuntu.
  • steinybot
    steinybot about 4 years
    Using 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
    dvdmn almost 4 years
    even though I cannot find the file on terminal or finder, opening the file with text editor works... thanks
  • Sharpey
    Sharpey over 3 years
    if ls ~/.ssh/*.pub display nothing you need to generate your public key first. This was my issue on new machine.
  • Parthi
    Parthi over 2 years
    Generate one if ssh key is not there already. As mentioned in one of the response.