Last Updated: June 06, 2022
·
54.76K
· jasonyost

pbcopy on Ubuntu/Linux

pbcopy is an awesome tool on Mac, but the actual program is not available on Ubuntu.

The functionality can be replicated in a few simple steps on Ubuntu, or any distro of linux with a few modifications.

sudo apt-get install -y xclip

Open .bashrc and add an alias

alias pbcopy="xclip -sel clip"

Close the editor and execute source ~/.bashrc

Now executing pbcopy < ~/.ssh/id_rsa.pub for example will copy your public SSH key to the clipboard

ZSH users can follow the same steps, replacing .bashrc for .zshrc

Take it one step further by adding an additional alias of alias cpkey="pbcopy < ~/.ssh/id_rsa.pub" to copy your SSH key with just cpkey in ther terminal.