Super User is a question and answer site for computer enthusiasts and power users. 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

How to programatically generate a password for a GNU screen session?

Normally, to define a password for an existing GNU screen, we have to:

  • Start a screen
  • Do Ctrl+A :password
  • Upon reattach, screen will ask for the password

And to apply the password to new screen sessions:

  • Do Ctrl+A ]
  • Copy the encrypted password
  • Put the encrypted password in ~/.screenrc (or some custom file) preceded by password statement
  • Upon next start (screen -c "/path/to/custom_screenrc for custom files), screen will ask for the password

That's a lot of manual steps to have an encrypted password generated.

I want to run a command to generate the encrypted password to be put in .screenrc.

share|improve this question
up vote 2 down vote accepted

GNU screen uses GNU crypt C library (wikipedia, manual) with DES encryption and a random salt comprised of 2 random uppercase alphabetic characters.

So, let's use mkpasswd from whois package that relies on the same library:

sudo apt-get install whois

Then generate the encrypted password:

(echo -n "password "; mkpasswd -m des -S SO "test") >> ~/.screenrc

Next time you'll start a new screen, it will ask for the password.

Alternative to apply the password only to certain (new) screens:

tmpconfig="$(mktemp /tmp/.screenrc-XXXXXX)"
(echo -n "password "; mkpasswd -m des -S SO "test") > "$tmpconfig"
screen -c "$tmpconfig"
rm "$tmpconfig"

You can safely delete the temp config file once screen is started. Encrypted password is stored in memory once started.


  • test is the password.
  • SO is the salt. You can keep this salt, or replace it by whatever 2 uppercase alphabtetic characters, i.e. ^[A-Z]{2,2}$ in regexp language. Just for info (and for brute-forcers), the first two characters of the encrypted password is indeed the salt.
  • For a small added security of temporary screen conf files, store it in RAM instead of hard drive, by using /run/shm instead of /tmp.
share|improve this answer

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .