I'm trying to figure out a way in which I can boot TMUX under a user other than root, but automatically whenever Linux starts.

At least that's what I think I need. What I want is to be able to SSH into a remote box using the aforementioned user and type "tmux attach" and see the running program that was launched when TMUX was started.

The issue seems to be that I can't get TMUX started under the user of choice via the rc.local file (Linux CentOS 6.3), but instead it seems the TMUX session belongs to root instead. Normally not a problem, but I want to use SSH and don't wish to try to use SSH as root.

Is there a way to "switch" to a different user while executing the rc.local script? BTW, I do have TMUX booting and launching my program via script but I need to be logged in as that user in order to see the program using SSH.


Any user can run something at boot time by adding a crontab entry with @reboot instead of a time. Edit the user's crontab (crontab -u joe -e as root or crontab -e as joe) and add a line like:

@reboot /home/joe/bin/start-tmux

where start-tmux is a script that starts your tmux session.

  • That's an interesting item to know about cron. I've never used it, but may now. I ended up using: su username -c "./tmux.script" in the rc.local file. Apparently, the error in my prior way was using what are now the contents of my tmux.script directly within the rc.local file. – Gary Apr 9 '13 at 14:41

Init scripts are run under the root user. Use su to change to the user in question:

su nonprivileged_user -c 'tmux commands go here'
  • Thank you, I did try that. For some reason, it does not work. Since it's during init, I cannot see why. The first command is: su username -c tmux start-server. That works. The rest appear not to. Most importantly, the command: su username -c tmux send-keys -t session_name:1 "sudo ./program arguments" C-m doesn't load. Attaching to TMUX via SSH brings me to a tmux shell. – Gary Apr 5 '13 at 22:26
  • I'm getting the impression the rc.local file is being "held up" with the first command: su username -c tmux start-server, instead of executing the line and going to the next line in rc.local. – Gary Apr 5 '13 at 22:38
  • @Gary You can always append something like > some.logfile 2>&1 to log a command's output – Tobias Kienzler Nov 25 '13 at 8:45
  • @Gary optionally 2>&1 | tee some.logfile which does the same, but also echoes the output on the screen. tee -a would append to the file (like >> would do). – peterph Nov 25 '13 at 23:06
  • I tried this option, but quickly found that I would have to set up all my user environmental variables in rc.local, which doesn't seem appropriate. (for example by path) – isaaclw Sep 6 '14 at 17:53

Wrote a little article here on this subject, check it out. https://kerpanic.wordpress.com/2017/03/30/loading-tmux-on-boot-in-linux/

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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