[ssh] Copying a rsa public key to clipboard

I am trying to copy a public key to the clipboard on macOS, but I keep getting "no such file or directory." The command I am using is pasted below

pbcopy < ~/.ssh/id_rsa.pub

This question is related to ssh clipboard

The answer is


Your command is right, but the error shows that you didn't create your ssh key yet. To generate new ssh key enter the following command into the terminal.

ssh-keygen

After entering the command then you will be asked to enter file name and passphrase. Normally you don't need to change this. Just press enter. Then your key will be generated in ~/.ssh directory. After this, you can copy your key by the following command.

pbcopy < ~/.ssh/id_rsa.pub 

or

cat .ssh/id_rsa.pub | pbcopy

You can find more about this here ssh.


cat ~/.ssh/id_rsa.pub

then you can copy your ssh key


To copy your public key to the clipboard

cat ~/.ssh/id_rsa.pub | pbcopy

This pipes the output of the file to pbcopy.


With PowerShell on Windows, you can use:

Get-Content ~/.ssh/id_rsa.pub | Set-Clipboard

cat .ssh/id_rsa.pub | bcopy

This works for me.


For using Git bash on Windows:

cat ~/.ssh/id_rsa.pub > /dev/clipboard

(modified from Jupiter St John's post on Coderwall)


Another alternative solution, that is recommended in the github help pages:

pbcopy < ~/.ssh/id_rsa.pub

Should this fail, I recommend using their docs to trouble shoot or generate a new key - if not already done.

Github docs


Another alternative solution:

cat  ~/.ssh/id_rsa.pub |  xsel -i -b

From man xsel :

-i, --input

read standard input into the selection.

-b, --clipboard

operate on the CLIPBOARD selection.


Window:

cat ~/.ssh/id_rsa.pub

Mac OS:

cat ~/.ssh/id_rsa.pub | pbcopy

Does the file ~/.ssh/id_rsa.pub exist? If not, you need to generate one first:

ssh-keygen -t rsa -C "[email protected]"

Check the path where you have generated the public key. You can also copy the id_rsa by using this command:

clip < ~/.ssh/id_rsa.pub