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
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
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.