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.

- 6,818
- 9
- 52
- 103

- 2,101
- 4
- 14
- 15
-
9It is infuriating that there is no clue why the question is unsuitable, and equally infuriating that we can't vote out the administrator who is responsable, for he is anonymous. – Albert van der Horst Dec 14 '21 at 10:20
-
@AlbertvanderHorst The people responsible for closing questions are not anonymous; you can find them in [the timeline](https://stackoverflow.com/posts/32039476/timeline#history_6ccd9074-0448-4f8b-9a1f-a9256d1583b6). – smitop Dec 18 '21 at 12:34
5 Answers
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.

- 3,539
- 2
- 20
- 28
-
5if someone wants to use `alias` for this you can do this: `alias cpc="xclip -sel c < "` and you can use it like so: `cpc file_name.txt`; cpc stands for copy contents – alexzander Jun 28 '21 at 11:23
-
1This only works when you remain in the linux sphere, if it needs copy to clipboard from a Windows app/tool, you're still confined to cat and then selecting the text on display. Anyone's got a better solution for that? – Julius Aug 30 '21 at 13:55
-
6
-
1
In macOS (but maybe also in Linux operating systems) you can do the following that will directly copy the content of id_rsa.pub to clipboard:
pbcopy < ~/.ssh/id_rsa.pub

- 1,176
- 16
- 32

- 1,765
- 11
- 9
-
1thank you for posting this answer despite the fact that others would insist on ONLY "linux". I certainly found this useful when i searched for "how to copy from unix terminal clipboard in mac" – Sidharth Ghoshal Oct 14 '22 at 17:31
This command copies the content of a file into your clipboard:
xclip -selection clipboard -i < file.txt
Also, this shorter command copies the content of a file into the mouse middle click:
xclip < file.txt

- 1,176
- 16
- 32

- 1,649
- 1
- 20
- 22
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.

- 57
- 1
- 4
-
12If the file is larger than the screen (for instance when using vim) then this doesn't really work. Only copies the part you have selected – Joe Phillips May 28 '21 at 18:56
You can use:
cat ~/.ssh/id_rsa.pub
I hope that help you, if not:

- 7,626
- 5
- 15
- 33

- 392
- 4
- 5
-
17this only displays it, not copies to clipboard. if you have a really large text, it's not practical to try to highlight it all – ahnbizcad Oct 28 '20 at 23:41
-
11
-
45missing piece: `manually highlight & copy the output of this command with a mouse on the terminal` – Dut A. Jan 29 '21 at 17:32
-
2
-
@Timo Because the issue with the vi is the scroll to copy the content. So if the user just wanted to do it once, it's ok – entropyfeverone Apr 11 '22 at 11:04