0

I have built a headless Ubuntu Server 18.04 (without GUI). This is a simulated environment built in VirtualBox meant to simulate a production scenario that I am faced with configuring very soon. The production environment will be remote and accessed via a VPN. Please note that VirtualBox is not part of the production scenario.

I have created a private/public ssh key pair for using in GitHub so I can add a new deploy key

I need to be able to get a copy of the public key to add to GitHub.

There is no clipboard with a headless server via terminal. I tried installing and configuring xclip/xsel to behave like pbcopy/pbpaste. This works great on Ubuntu with a GUI but doesn't work on a headless server via terminal.

Trying to use xclip like this:

DISPLAY=:0 xclip -sel clip < ~/.ssh/id_rsa.pub

results in:

Error: Can't open display: :0

I tried getting OpenSSH up and running. I'm not an SSH guru and haven't gotten that to work.

Are there any other ways to get that ssh public key from the headless server? It is a remote server with no physical access.

2

2 Answers 2

2

In the normal circumstances you will be able to access your remote Ubuntu server via SSH. For this purposes, on your desktop machine, you will use a terminal emulator as gnome-terminal (on Ubuntu) or PuTTY (on Windows), etc. So you will be able to do cat id_rsa.pub, then copy the content of the key from the terminal window in use and paste it in the Key field in your browser's window. Actually in this way you will use the clipboard of your (local) desktop system.


What you need is installed openssh-server on the remote instance and openssh-client on the local (desktop) instance. Use the following commands to do that:

sudo apt install openssh-server
sudo apt install openssh-client

Then you must have an IP address (or a domain name) of the remote instance, which you can access from the local instance, no mater directly, through VPN, SSH tunnel, etc. In your case you can use ifconfig to find the IP address of the Ubuntu Server in your LAN.

The basic syntax of the ssh command is:

ssh user@host     # where host IP address or domain name

You should execute that command within a terminal window on the local (desktop) system. Then you will be able to operate freely (depending on your user's rights) on the remote server with the pleasure of the GUI environment :)

enter image description here


Further reading:

2
  • 1
    If you're using the VirualBox console directly (rather than a 3rd party terminal session such as PuTTY), it should be possible to copy the terminal output from guest to host via shared clipboard, so long as Guest Additions are installed Mar 4, 2019 at 18:24
  • @steeldriver VirtualBox is not part of my production scenario as stated in the original question. Thank you for trying to help though.
    – joshblair
    Mar 5, 2019 at 18:19
0

The difference between the issue I am asking about and the question/answer that everyone is point to is this: I have a headless server (no GUI), just a server-based terminal that doesn't support a clipboard, mouse, etc. I can 'cat' out the public key just fine. I was looking for an easy way to copy that. I installed xsel and xclip but those utilities don't work without a clipboard.

My Solution: ftp the public key file to a remote server. It's a hack but works.

1
  • The "x" in front of xsel and xclip imply they are dependent on x.org GUI. Since Ubuntu server does not have a GUI (headless or not) these won't work. See askubuntu.com/questions/305654/xclip-on-headless-server The first part of your answer is a comment. Please focus your answer to the solution to the problem.
    – user68186
    Mar 5, 2019 at 18:50

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.