Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

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.

share|improve this question
add comment

2 Answers

up vote 2 down vote accepted

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.

share|improve this answer
    
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
add comment

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'
share|improve this answer
    
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
add comment

Your Answer

 
discard

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.