Copy file contents to the clipboard in Linux terminal

LinuxGitGithubSsh

Linux Problem Overview


I'm generating an SSH key but I don't know how to copy the key from id_rsa.pub to the clipboard. I'm using BackBox Linux.

Linux Solutions


Solution 1 - Linux

xclip -sel c < input_file

will copy the contents of input_file to clipboard. xclip requires installation. To install

sudo apt install xclip

-sel stands for -selection. c is for clipboard. Interchangeable.

Capable of much more, I advise reading its man page.

There is also xsel. This answer on Unix SE gives a very thorough answer to this exact question.

Solution 2 - Linux

xclip -selection clipboard -i < fileName

copies the content of file into clipboard

Solution 3 - Linux

You can do the following that will directly copy the content of id_rsa.pub to clipboard:

pbcopy < ~/.ssh/id_rsa.pub

Solution 4 - Linux

If you're copying from terminal (like if you use the cat command already posted), highlight the key details and use Ctrl + Shift + C. This should put it on your clipboard. You can also right click and select 'copy' from terminal.

Solution 5 - Linux

You can use:

cat ~/.ssh/id_rsa.pub

I hope that help you, if not:

Set up SSH for Git and Mercurial on Mac OSX/Linux

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionRavi ShankarView Question on Stackoverflow
Solution 1 - LinuxHaggraView Answer on Stackoverflow
Solution 2 - LinuxFiroj SiddikiView Answer on Stackoverflow
Solution 3 - LinuxYu N.View Answer on Stackoverflow
Solution 4 - Linuxe_mView Answer on Stackoverflow
Solution 5 - Linuxwilliam.bonillaView Answer on Stackoverflow