I've been using gnu screen for many years, and I've been looking into switching to tmux.

I can't figure out how to make tmux require a password when attaching to a session. In gnu screen, I use the :password command to set a password. Then after detach, subsequent attaches to the session using screen -x requires the password to attach.

How do I configure tmux to do the same? I've done some googling, and I get the impression that this isn't possible. That's a show-stopper for me. I like tmux, but if it doesn't support password-protected session attaches, I can't use it.

1 Answer 1


This isn't possible with tmux yet. You can only lock the terminal so far. The developers argue something about if someone has access to another shell on the system then you are toast anyway.

However, I've come up with a quick solution using file permissions and attributes to lock things up. I've put it together into 3 bash files which you would have to add to your $PATH.



if [[ ! -d ~/.tmux-sessions ]]; then
    mkdir ~/.tmux-sessions

tmux -S ~/.tmux-sessions/secure

Once you want to exit your session, do so normally with ctrl+b,d -- then you would want to run lock.sh shown below.



chmod 000 ~/.tmux-sessions
sudo chattr +i ~/.tmux-sessions
sudo -k

This will lock the socket used to connect to tmux. Nobody will be able to access it until you remove the immutable attribute from the socket directory and change the permissions back to normal. Luckily we can create a script for this, too:



sudo chattr -i .tmux-sessions
chmod 770 .tmux-sessions
tmux -S ~/.tmux-sessions/secure attach

With that you should just be able to run attach.sh, which will ask you for your user password to re-open.

Hope this hack helps!

For just locking your terminal.

First you need to have vlock installed.

sudo apt install vlock

or whatever package manager command you use.

Then you set tmux to use vlock

echo "set-option -g lock-command vlock" >> ~/.tmux.conf

Then when you are in tmux, you can do:


That will lock the terminal. The caveat is someone could still attach to the session from another terminal. I'm looking to see if there is a way to prevent that as well.

  • Will it lock all the tmux sessions or there is a way to lock a particular tmux session?
    – Naga Kiran
    Dec 7, 2021 at 14:04
  • It is the command starting with "sudo" in attach.sh that is requiring the password, correct?
    – melutovich
    Aug 2, 2022 at 19:25
  • @NagaKiran As he has designed it, it looks to be just for "one" session defined by the "secure" file for the session plus the directory (called .tmux-sessions) is make immutable on lock and removing that attribute on unlock
    – melutovich
    Aug 2, 2022 at 19:32
  • @NagaKiran, vlock supports -a option: lock all virtual consoles by preventing other users from switching virtual consoles.. What if?: set -g lock-command 'vlock -a || vlock';.
    – Artfaith
    Dec 9, 2022 at 9:26

You must log in to answer this question.

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