Ask Ubuntu is a question and answer site for Ubuntu users and developers. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I have used the wpa_passphrase command and I get something like this:

network={ ssid="blahblah" #psk="moreblahblah" psk=d5e532ecca53ea963e5b3b5521bb3682c53fcf5b6d55f15622027145c795b661 }

I need to copy that "psk=[long string]" to my wpa_supplicant.conf file. How can I select it in order to copy it? And then what command do I use to copy it? Such that in my favourite text editor I can press a paste command to paste it? (ps. I don't have a mouse )

share|improve this question

if you have a touchpad though, highlight the text and press Ctrl + Shift + C to copy ...

the following resources describe how to copy/paste using keyboard only -- screen/byobu:

How do I integrate Byobu's copy-buffer with the X clipboard?

Copy and Paste in Scrollback mode (screen/byobu)

  • Enter scrollback mode: Ctrl+A+[ or in byobu also F7
  • Move the cursor to the start of the text you want to copy, hit spacebar
  • Move the cursor to the end of the text you want to copy and hit enter again
  • To paste text, hit Ctrl+A+] or Alt+Insert
share|improve this answer
This information isn't quite right for byobu. Copy in byobu is Spacebar then Enter, per the byobu manual. Differs slightly from screen in that way. I only mention it here because this post happens to rank very highly on google for "copy/paste in byobu". – philo Aug 18 '12 at 1:45

Try this:

wpa_passphrase | awk '/psk/ {print $4}' >> wpa.supplicant.conf

Command should take out the "psk=d5e532ecca53ea963e5b3b5521bb3682c53fcf5b6d55f15622027145c795b661" part and copy it to the end of your wpa.supplicant.conf file. Try changing $4 to $3 or $2 if you don't get the right part of the wpa_passphrase command.

share|improve this answer

May be not perfect but a workaround. May be you could write the output in a file then go into the file remove unnecessary text and using cat you could append it to wpa_supplicant.conf

Basically your workflow would be:

command > rough

nano rough here delete the unnecessary text and keep just the necessary ones i.e psk

sudo sh -c "cat rough >> wpa_supplicant.conf"

Or may be you could use vim to yank the required text choosing it in visual mode.

P.S. Someone with good knowledge of sed would give you a easier solution than this I think.

share|improve this answer
the sudo sh ... command could be written as: cat rough | sudo tee -a wpa_supplicant.conf. – Lekensteyn Apr 28 '11 at 7:34

The next sed command will fetch the key (which consists of characters from the hexadecimal set) from the output of wpa_passphrase and put it in a temporary file pass.

wpa_passphrase | sed 's/.*psk=\([0-9a-f]*\).*/\1/' > pass

As you do not have a mouse, you cannot just select and copy it. We'll use the nano texteditor for inserting this pass:

nano wpa_suppliciant.conf

Move to your desired location using your arrow keys and press Insert. Enter the name of the file you've just created, pass, followed by an Enter. Quit & save the result by pressing Ctrl + X and confirm it by entering Y followed by an Enter.

share|improve this answer

Of course the most common way to do this would be to use a mouse or other pointing device (such as a touchpad). Although it's somewhat excentric, it's possible to copy text without a mouse. (You may of course have a valid reason not use a pointing device.) Check out xclip, as in this answer. Thus you could use:

wpa_passphrase | xclip -sel clip
share|improve this answer

You can setup a keybinding in byobu to be able to send the text selected in byobu's buffer into the X clipboard.

Add the following to ~/.byobu/keybindings

# Add cool line to make copying to x clipboard possible.
# This binds C-a b to copy screen's copy buffer to the system clipboard.
bind b eval writebuf 'exec /bin/sh -c "xsel -i < $BYOBU_RUN_DIR/printscreen"'

Then after using the usual F7, move, space to start select, move, enter to save to buffrer, then you can use C-a b (Ctrl-a, then b) to save it to the clipboard

(Based on

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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