Archive for the ‘tmux’ Category

Refresh a stale tmux session

Posted on March 31st, 2011 in ssh, tmux | 3 Comments »

Sometimes when you SSH into a machine and reattach your tmux session you’ll find that your SSH environment variable is stale so commands like “git pull” don’t work. Here’s a simple command that refreshes that variable. I simply type “r” anytime I notice my session is stale or a command requiring ssh authentication fails:

# used to refresh ssh connection for tmux 
# http://justinchouinard.com/blog/2010/04/10/fix-stale-ssh-environment-variables-in-gnu-screen-and-tmux/                                                                                                                                                                                         
function r() {   
  if [[ -n $TMUX ]]; then
    NEW_SSH_AUTH_SOCK=`tmux showenv|grep ^SSH_AUTH_SOCK|cut -d = -f 2`
    if [[ -n $NEW_SSH_AUTH_SOCK ]] && [[ -S $NEW_SSH_AUTH_SOCK ]]; then 
      SSH_AUTH_SOCK=$NEW_SSH_AUTH_SOCK  
    fi
  fi
}


I can’t take credit for this wonderful tidbit, it was written by Eivind Uggedal in a comment in this post.

Sharing remote terminal session between two users with Tmux

Posted on January 2nd, 2011 in tmux, unix | 6 Comments »

I’ve yet to write my “Wonders of Tmux” entry but always have small tidbits to give in the meantime.

Sometimes sharing your whole desktop via Skype, Teamviewer, or some other screen-sharing system is overkill, at the very least harder to read and control remotely. Sharing a terminal session between two (or more) users is great for pair programming (especially if both users are vi or emacs users) or for one user to educate, walk-through, or troubleshoot something with another remote user – also great for showing how Tmux works! One can even split the screen in half and be SSH’d into multiple machines together!

There’s three ways that users can share a terminal session together. The first way requires a little more work from the person sharing their tmux session, the second and third require either sudo rights or being able to su to the other user’s account.

Similar to SSH, when you create a tmux session, it creates a temporary socket in the /tmp directory with the tmux user owning the file. This makes it unaccessible by other users.

Allow another user access to your tmux session:

# specify the name of your tmux socket with -S when creating it
tmux -S /tmp/pair
# chmod to allow other users to access it
chmod 777 /tmp/pair
 
# now the other user can connect with
tmux -S /tmp/pair attach

Sudo your way into another users tmux session

# Have the user create a tmux session
# ls -al /tmp to see which tmux session is owned by the user you want to share sessions with then
# in the following example tmux-502 is the tmux socket folder of the example user 
sudo tmux -S tmux-502/delfault attach

su your way into the session

su username # need user's password or sudo
tmux attach

Installing Tmux 1.4 from source for Centos

Posted on January 2nd, 2011 in tmux, unix | 2 Comments »

The newest version of Tmux (1.4, released Dec 2010) has a bunch of fixes and subtle workflow enhancements. Unfortunately Yum still only has 1.3.

You can compile it from source here. I did and got the following errors:

# ./configure
Configured for Linux
# make
cc -DBUILD="\"1.4\"" -std=c99 -D_GNU_SOURCE -D_POSIX_SOURCE -iquote.   -c -o attributes.o attributes.c
In file included from attributes.c:23:
tmux.h:30:19: error: event.h: No such file or directory
In file included from attributes.c:23:
tmux.h:830: error: field 'name_timer' has incomplete type
tmux.h:1032: error: field 'key_timer' has incomplete type
tmux.h:1093: error: field 'event' has incomplete type
tmux.h:1117: error: field 'repeat_timer' has incomplete type
tmux.h:1139: error: field 'identify_timer' has incomplete type
tmux.h:1142: error: field 'message_timer' has incomplete type
make: *** [attributes.o] Error 1

After checking around, I discovered I was missing these two packages:

yum install libevent-devel
yum install ncurses-devel ncurses

Recompile and you should be golden.

Addendum: on a fresh Ubuntu install it’s:

apt-get install libevent-dev
apt-get install libncurses5-dev libncursesw5-dev

Fixing Tmux create session failed: : Exec format error

Posted on January 2nd, 2011 in tmux, unix | 2 Comments »

This error happened to me whenever I tried to run Tmux as a non-root user. Most likely if this is happening to you, you’re using Linode VPS like I am or have a similar setup.

The answer is that devpts is missing. Trying running the following as a non-root user, and Tmux should work:

sudo mount devpts /dev/pts -t devpts

What is devpts?

You probably don’t want to run this command every time (or give your users access to sudo.)
Add this to your /etc/fstab and you can continue with your tmux screen splitting.

tmpfs /dev/shm tmpfs defaults 0 0 
devpts /dev/pts devpts gid=5,mode=620 0 0 
sysfs /sys sysfs defaults 0 0