Question

copy and paste into console

Posted May 2, 2016 139k views
APIControl Panels

How do you copy and paste into the console?

6 comments

These answers are provided by our Community. If you find them useful, show some love by clicking the heart. If you run into issues leave a comment, or add your own answer to help others.

×
Submit an Answer
34 answers

I had a machine crash, and needed to setup another one with SSH access. I got the console login ok, but no way to paste my public key there. Just spent a whole day trying to find a way to do this.

My solution, finally was to put the public key on a public dropbox folder, then in the console, use:

curl 'https://dl.dropbox.....' > temp1
cat temp1 >> .ssh/authorized_keys

The attached JS snippet never worked for me, and I didn’t have the patience to debug/improve the snippet (maybe that was a mistake since I wasted a whole day). Some versions drop characters, some changed them, some capitalize during the script paste action.

I might understand security issues which caused DO to decide not to allow copy-paste in the console, but they must supply an alternative way to upload an SSH key.

This issue is from 2013. It’s about time DO solved this.
Thanks.

  • Geez. Thanks for this. This worked for me. I used ‘wget’, but with the same results.

  • What a simple yet ingenious solution to counter DO’s archaic console! wget worked too :)

  • THANK YOU for this simple, elegant solution

  • Thanks, saved a lot of hassle.

  • To avoid scripts that don’t work or having to use DropBox (for security reasons):

    1. Login to the console on digitalocean website.
    2. Type sudo nano /etc/ssh/sshd_config
    3. Change PasswordAuthentication from “no” to “yes” and save the file
    4. Open a terminal on your computer and type ssh username@[hostname or IP address] or if on a Windows box use PuTTY for password login making sure authentication parameters aren’t pointing to a private key
    5. Login with password
    6. Type sudo nano ~/.ssh/authorized_keys
    7. Paste public key text here and save the file
    8. Type sudo nano /etc/ssh/sshd_config
    9. Change PasswordAuthentication from “yes” to “no” and save the file
    10. Log out and attempt to log back in (if using PuTTY make sure you set up auth parameters to point to your private key)

    Since the public key is now safely in the authorizedkeys file, you can use the console on the digitalocean website to troubleshoot if you are still having issues (like permissions or sshdconfig settings) that may still be locking you out.

  • Great solution, thanks!

    Just an FYI that Dropbox seem to have changed their policy… You can no longer publicly view a .pub file. Neither can you view a file without an extension. At least, I can’t so I presume it’s the same across the board.

    Couldn’t work out why CURL wouldn’t work - until I loaded the Dropbox URL in a browser to check (probably should have done that anway).

    I just changed the Dropbox file extension to .txt and it worked OK.

  • This is freakin’ brilliant! I’m happy to send you some beer money for this! :-)

  • I also found you can use wget to download a file from dropbox. So you can also use this approach.

    wget 'https://www.dropbox.com/s/PATH/TO/FILE/FILE-NAME.TXT?dl=1'
    cat FILE-NAME.TXT >> .ssh/authorized_keys
    

    The important difference is the presence of dl=1 at the end of your dropbox link.

  • This is 100% the right work around to the copy/paste console problem. Thanks for the help.

  • My dear Sir, You saved my day! :)

  • Best answer. I got a new droplet without login but had no way to access it. Thank you for this :)

What I can share is how to paste command lines in the console.

  1. Copy the console URL and paste it to a new window.
    ex. https://cloud.digitalocean.com/droplets/111111111/console?no_layout=true.

  2. Open Developer Tools then click Console tab

  3. Copy and paste the codes below. Taken from stackoverflow

    var sendString = (function(rfb, force, sendDelay) { 
    sendDelay = sendDelay || 25;
    var _q = [];
    var _qStart = function() {
    var chr = _q.shift();
    if (chr) {
      rfb.sendKey(chr);
      setTimeout(_qStart, sendDelay);
    }
    };
    var _qStop = function() { _q.length = 0; };
    var fn = function sendString(str) {
    _qStop();
    str = str || '';
    var chr;
    for (var i=0; i < str.length; i++) {
      chr = str[i].charCodeAt();
      _q.push(chr);
    }
    _qStart();
    };
    if (rfb.sendString && true !== force) {
    console.warn('rfb.sendString not installed because it already exists.  Use force if you\'d like');
    }
    else {
    rfb.sendString = fn;
    }
    return fn;
    })(rfb);
    
  4. On the same console type sendString(“Commandline to be pasted in the console”)

NOTHING works on Digitalocean anymore. YOU can’t copy paste, the console window is NOT scrollable with FF, Safari and Chrome. SSH Login from droplets don’t work evenso pinging is good, DIGITALOCEAN GETS WORSE AND WORSE. They changed, they know have incompetent staff, wrong people in charge for Keytechnology, trying to optimise cost structure etcetera. The divers issue atm with DO makes me run away. I think it will not get better but more worse in future…

  • This is very irritating as I have long passwords stored in my password manager. Not going to type those in manually, so the console is kind of useless to me.

Let’s try to REQUIRE DIGITAL OCEAN to change it’s UGLY interface: no one works today without copy/paste.

Hi, I have developed the following script based on another one, i lost its link

What I did is that I made it so it sends the whole text/cmd in one go also I added the ability to send line breaks when typing “\n” into the text, finally I made it so click enter at the end of each command.

The script is in a bookmarket format, just create a bookmarket and paste the following script into the address field

javascript: (function () {
    var s = prompt("Enter text to be sent to console, (This wont send the enter keystroke)");
    s = s.replace(/\\n/gi, String.fromCharCode(13));
    var t = s.split("");
    t.push(String.fromCharCode(13));
    console.log(t);
    var i = [];
    t.forEach(f);
    console.log(i);
    rfb._sock.send(i);
    function f(character) {
        var code = character.charCodeAt();
        var needs_shift = "!@#$%^&*()_+{}:\"<>?~|".indexOf(character) !== -1;
        var shift = XK_Shift_L;

        if (needs_shift) {
            key(shift, 1);
        }
        key(code, 1);
        key(code, 0);
        if (needs_shift) {
            key(shift, 0);
        }
    }
    function key(keycode, down) {
        i = i.concat(RFB.messages.keyEvent(h(keycode), down));
    }
    function h(e) {
        switch (e) {
        case 13:
            return XK_Return;
        default:
            return e;
        }
    }
})();
  • This worked great for me. thanks! just be sure to run the console in a separate browser window and refresh the window after you create the bookmark.

  • Seems to work in my specific case, thanks mate!

    ps. What won’t work yet it’s that bloody Console, which is crap. But at least now I can copy/past things…

  • Even DigitalOcean got locked out of my VM, strange that it requires the Primary NIC to work in order to Power On/Off and Resize (This one I can understand the need for communication with Guest) but Power is Host Specific

    The only thing that worked was the Console, and of course thank’s to it being a lag-fest typing so many characters was impossible.

    Thank you for this!

such a bullshit console. i just wanted to add one more ssh pub key to our server. And i cannot login through the old ssh pub key. So what i have to do is,

  1. Open digital ocean panel click the access button then i will received a crazy long temp password like: 1hj2123h123h12h31lk2n31lk2n
  2. Open the console from digital ocean website, enter this bullshit password manually because do console didn’t support copy&paste.
  3. I will be required to reset the password, then that means i have to enter that password one more time!!!
  4. After reset, i try to edit the know_hosts file under ~/.ssh/, then once again, i cannot paste the ssh pub key. So i have to enter those pub key manually??? Can you believe it?
  5. Then i decided to switch to mac terminal, but i have to enable password login on remote server.
  6. Enable that password login support.
  7. Finally i add that pub key.

No copy and paste on console? Please add the feature, stop wasting our time!

I found a simple solution to this problem :

  1. Create a gist on github and copy the ssh key there on the gist. 2.Login to your terminal using user name and password then navigate to your ssh folder.
  2. Take a backup of your authorized_keys file and save it with different name.
  3. Now use wget command to fetch the file

    wget https://gist.githubusercontent.com/.../gistfile1.txt
    
  4. Use ls to confirm the name of the file you just downloaded.

  5. Append this new file contents to your authorized keys using cat command

    cat gistfile1.txt >> authorized_keys
    

    Done. You can now login using your public key.

  • A brilliant solution to an extremely ridiculous problem that Digital Ocean refuses to solve. I’m moving over to Azure next month. This has been an ongoing issue and I realize these might be edge cases but when their answer is to ignore the problem…

How is this still broken 4 years later. The only thing I should need a web-based console for is resetting passwords or adding SSH keys, both require being able to paste into the console. Shameful.

To add your SSH key via copy & paste from your local terminal to your console - to establish the SSH connection - as explained. You need to copy the console window URL (at the top of the pop up browser frame) then add this URL to a new tab in your chrome browser - then in your chrome browser go to View>Developer>Developer Tools>Console & enter this minimised script (below) - which will enable you to PASTE your copied SSH key into the console no problems. As per answer on github https://gist.github.com/croepha/7b53f211ae4be3c526c3

!function(){function t(){function n(t,e){s=s.concat(RFB.messages.keyEvent(t,e))}var o=e.shift(),s=[],i=o.charCodeAt(),c=-1!==’!@#$%^&*()+{}:“<>?~|’.indexOf(o),r=XKShiftL;c&&n(r,1),n(i,1),n(i,0),c&&n(r,0),rfb.sock.send(s),e.length>0&&setTimeout(t,10)}var e=prompt("Enter text to be sent to console, (This wont send the enter keystroke)”).split(“”);t()}();

Hey everyone,
I’m a product manager here at DigitalOcean and I wanted to send a quick update about this issue. We just released the ability to paste text into our Cloud console! Give it a try and let us know if there is anything else we can help with.
Thanks,
Keith

  • Text gets badly mangled on paste

  • Text still gets mangled and truncated. Does your team test with pasting text of any size, like, say, an ssh-key to verify it works correctly?

    Edit: while we’re at it, having the terminal screen size get updated when the windows is resized would be a reasonable feature too… (if you guys actually care about customer experience).

  • It doesn’t work for me.

    In my case, I’m copying a public key. When I open a text editor from the console, right click and paste, a series of undesired input seems to occur, interpreted as a bunch of commands. One of those commands seems to quit my editor, so now all this random input is being entered directly into the command line, a bunch of stuff scrolls by as god knows what commands are executed on my droplet.

    Terrifying stuff.

Previous 1 2 3 4 Next