Thursday, February 19, 2015

Starting with tmux - putting in initial settings

After a few years using GNU screen as my main terminal multiplexer, I have now changed it to tmux. The reasons behind that are:

  1. A lot more customizable
  2. The commands are also available in easy human understandable language, rather than just the shortcuts. For example: to kill a window, just "ctrl-b" and type "kill-window" or "killw", which is easier for new user like me to remember and use, rather than shortcuts like "ctrl-b &" which sometimes can be confusing.
  3. Easier horizontal and vertical splitting mechanism

To start with tmux, especially if you are coming from screen, it is very important to set th ekey binding right, since ctrl-b is not easily reachable with one hand compared to ctrl-1. Below are my initial .tmux.conf settings, to ease up my transition from GNU screen to tmux.

$ cat .tmux.conf
# unbind control-b, and replace it with control-a (GNU screen style)
set-option -g prefix C-a
           unbind-key C-b
           bind-key C-a send-prefix
# Use vi or emacs-style key bindings in copy and choice modes
set-window-option -g mode-keys vi       
# start windows numbering at 1
set -g base-index 1
# renumber windows when a window is closed                     
set -g renumber-windows on              

So there you go, some very simple settings to be appended to .tmux.conf, to ease up your learning in using tmux. Please refer to the comments, to actually know what the settings are for. You can always refer to tmux manual (man tmux) for more settings.

Hope this will be helpful :)

Thursday, February 12, 2015

Accessing other user's screen session

This need usually arises, when in a multi user machine, you as an admin wanted to check what is other user is running using screen. The best you can see even as root using ps, is just the name of the command, like below:

michael@vbox:~$ sudo ps awxuf | grep -i screen

root      1135  0.0  0.0  13636   976 pts/1    S+   13:27   0:00                          \_ grep --color=auto -i screen

john   4245  0.0  0.0 387364 16668 ?        Sl   Feb02   0:06  |       \_ gnome-screensaver

1001      6762  0.0  0.0 347384 10428 ?        Sl   Feb02   0:00              \_ gnome-screensaver

john    625  0.0  0.0  31320  1568 ?        Ss   11:57   0:00 SCREEN -S test

michael@vbox:~$ pstree -Gap 625

screen,625 -S test

  └─bash,626



When you try to access the screen session using other user, this is usually the error:

michael@vbox:~$ sudo -u john screen -r 625
Cannot open your terminal '/dev/pts/1' - please check.


This is because, your terminal: /dev/pts/1 is only readable and writable to the owner of the terminal:


michael@vbox:~$ ls -lh /dev/pts/1
crw--w---- 1 john tty 136, 1 Feb  12 13:30 /dev/pts/1


To overcome this, simply allow read and write to the terminal, to all users:
john@vbox:~$ chmod o+rw /dev/pts/1
john@vbox:~$ ls -lh /dev/pts/1
crw--w-rw- 1 john tty 136, 1 Feb  12 13:32 /dev/pts/1


Once that done, you can use sudo to access the screen of the other user:
michael@vbox:~$ sudo -u john screen -r 625


Hope this help :).