Aim: I want to copy my public ssh key generated on AWS Server to my github account.

I have little experience with Ubuntu.
I use the ssh command from my laptop to connect to the AWS Server.
The operating system on both my laptop and AWS Server is Ubuntu trusty tar 14.04.

ssh -i /etc/ssh/aws_myhosts.pem ubuntu@XX.XX.253.101

This works.

I want to copy the contents of aws_myhosts.pem (my public ssh key) to my github account.

I can select the text using Vim (using pressing v first and keyboard arrows, no mouse is present), but can't copy and paste it to an external program (ie Github).

The problem occurs when I want to copy my public ssh key to Github.

I have installed vim-gtk as it has clipboard support. When I type

$ vim --version | grep clipboard  

I understand clipboard support is required.

It is said I should use "+y to copy text, but this has not worked.

What do I have to do to be able copy text from the terminal to external programs?

I've tried Accessing the system clipboard using Vim

  • can you clarify, Ubuntu is the server you connect to? you connect from your laptop? What OS on the laptop and what program to connect to the server ? and then you want to copy text from where to where? – Panther Apr 12 '15 at 2:23
  • @bodhi.zazen <br/> I can to connect to the AWS Server (this uses Ubuntu, trusty 14.04), from my laptop (this also uses Ubuntu, trusty 14.04).<br/> The command I use is <br/> Thanks. ssh -i /etc/ssh/aws_myhosts.pem ubuntu@XX.XX.253.101 <br/> With this I'm now connected to the AWS Server. <br/> Aim: To copy text from the console on the AWS Server to Github (my public key address field). <br/> – user397253 Apr 12 '15 at 10:06
  • Assuming you are running X on your laptop , select the text you want to copy with your mouse. Then go to your ssh terminal and hit the middle mouse button or push the wheel down. If you have a two button mouse, configure the mouse so that if you hit both buttons at the same time it emulates a middle mouse click. see also vim.wikia.com/wiki/Toggle_auto-indenting_for_code_paste – Panther Apr 12 '15 at 13:01
  • @bodhi.zazen, thanks but I don't have a mouse. Thank you for your time. – user397253 Apr 13 '15 at 21:24
  • @Muru, thanks for your answer, I'm working on it. This is all new to me, so I've not got it working yet. I'll get back to you with feedback, thanks again. – user397253 Apr 13 '15 at 21:25

To use the clipboard that way, you must have X forwarding enabled ssh -X (or ssh -Y, depending on the settings).

See How can I copy text to the system clipboard from Vim?.


Here is the answer I was looking for:

To connect type:

ssh -X -i /etc/ssh/aws_myhosts.pem ubuntu@XX.XX.XXX.XXX


  • -X Enables X11 forwarding

  • -i Identity file The identity file selects a file from which the identity (private key) for RSA or DSA is read.

  • /etc/ssh/aws_myhosts.pem is the private key file (used by Amazon web services)

  • ubuntu@XX.XX.XXX.XXX is the username at the remote host

When I typed the command above ie

ssh -X -i /etc/ssh/aws_myhosts.pem ubuntu@XX.XX.XXX.XXX

I received this message:

/usr/bin/xauth: file /home/ubuntu/.Xauthority does not exist

I used google to look up what this means from Look under the post from hwttdz

ie How do you ceate a .Xauthority file for remote access

This says, you will get a

 /user/bin/xauth: file/home/username/.Xauthority does not exist

But the .Xauthority file is made for you on the spot. Knowing that, you can then open up a graphic application from the remote machine, like

gedit filename

Which worked for me. I typed

gedit ~/.ssh/id_rsa.pub

which allowed me to copy the text I needed.


Rather a workaround, but you can just select the text and hit Ctrl+Shift+c to copy the selection to your clipboard


As a work around, use echo or cat instead of vim to view the file. Highlight the data and use your middle button or <ctrl-v> or <shift-insert> to paste, whichever works best for you.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.