Linux Screen to boost your remote productivity

Working remotely (via SSH) poses numerous challenges:

  • running programs are killed if the session is terminated or connection is lost
  • you need to open many connections if you want to run more things at the same time
  • you cannot resume the session from different machine

All above problems have a simple solution in Linux, called screen. Screen provides virtual terminals that can be disconnected & resumed later.

  1. Install screen
  2. [bash]sudo apt-get install screen[/bash]

  3. Prepare configuration file
  4. Below you can find example configuration file. This will enable changing the windows with F5/F6, scrolling and it will display some useful information in the bottom of your screen terminal. To enable it, just paste below text to file: ~/.screenrc
    [bash]
    #para tener scroll-back
    termcapinfo xterm|xterms|xs|rxvt ti@:te@
    defscrollback 5048
    ##
    ### detach on hangup
    autodetach on
    ##
    ### don’t display the copyright page
    startup_message off
    ##
    ### emulate .logout message
    pow_detach_msg "Screen session of $LOGNAME $:cr:$:nl:ended."
    ##
    #
    # BARRA DE ESTADO v1
    #### alternative caption, gives window list, LOGNAME and current date:
    caption always "%u%{wk}%?%-Lw%?%{bw}%n*%f %t%?(%u)%?%{wk}%?%+Lw %= %{mk}host:%H Load:%l %{ck}%M%{wk} %{ck}%d %{gk}%c"

    # BARRA DE ESTADO v2
    #hardstatus alwayslastline
    #hardstatus string "%{.bW}%-w%{.rW}%n %t%{-}%+w %=%{..G} %H %{..Y} %d/%m %C%a Load: %l"
    #caption always "%3n %t%? @%u%?%? [%h]%?"a
    #
    termcapinfo xterm ti@:te@

    defscrollback 1000

    # Scroll up
    bindkey -d "^[[5S" eval copy "stuff 5\025"
    bindkey -m "^[[5S" stuff 5\025

    # Scroll down
    bindkey -d "^[[5T" eval copy "stuff 5\004"
    bindkey -m "^[[5T" stuff 5\004

    # Scroll up more
    bindkey -d "^[[25S" eval copy "stuff \025"
    bindkey -m "^[[25S" stuff \025

    # Scroll down more
    bindkey -d "^[[25T" eval copy "stuff \004"
    bindkey -m "^[[25T" stuff \004

    bindkey -k k5 prev # F5 for previous window
    bindkey -k k6 next # F6 for next window
    [/bash]

  5. Create new virtual terminal
  6. [bash]
    screen -S sessionName
    # create new window: Ctlr-A and C
    # detach session: Ctrl-A and D
    [/bash]

  7. Reattach to previous session
  8. [bash]
    screen -dr sessionName
    # list existing session: screen -dr
    [/bash]

    Advertisements

NX server on Raspberry Pi

Finally I had some time to get my hand on new Raspberry Pi 2.
I think it’s useful to access the RPi2 by ssh (work out of the box) and NX. Installation of NX server is quite time-consuming, but I think it’s worth to give it a try! Here is what I did:

# install dependencies
sudo apt-get install xutils-dev expect xorg-dev libjpeg8-dev libpng12-dev cups xfonts-base x11-xserver-utils autoconf

sudo mkdir -p /usr/NX/{bin,etc}

# install freenx
wget http://pkgs.fedoraproject.org/repo/pkgs/freenx-server/freenx-server-0.7.3.tar.gz/856f597e139018f7ed62713c9d6c9ed5/freenx-server-0.7.3.tar.gz
tar xpfvz freenx-server-0.7.3.tar.gz
cd freenx-server-0.7.3
patch < gentoo-nomachine.diff
make
sudo make install

# copy node.conf
# and replace #COMMAND_MD5SUM="openssl md5" with COMMAND_MD5SUM="md5sum"
# and #COMMAND_START_GNOME=gnome-session with COMMAND_START_GNOME="/usr/bin/startlxde"
sudo cp node.conf.sample /usr/NX/etc/node.conf

# get nx source
wget http://code.x2go.org/releases/source/nx-libs/nx-libs_3.5.0.13-full.tar.gz
tar xpfvz nx-libs_3.5.0.13-full.tar.gz
cd nx-libs_3.5.0.13

# compile & relax for ~1 hour...
make build-full
sudo make install

# copy libs and binaries
sudo ln -s /usr/lib/NX3/lib/nx /usr/NX/lib
sudo cp -a nx-X11/lib/X11/libNX_X11.so* nx-X11/lib/Xext/libNX_Xext.so* nx-X11/lib/Xrender/libNX_Xrender.so* nxcomp/libXcomp.so* nxcompext/libXcompext.so* nxcompshad/libXcompshad.so* /usr/NX/lib
sudo cp -a nx-X11/programs/nxauth/nxauth nx-X11/programs/Xserver/nxagent nxproxy/nxproxy /usr/NX/bin

# link binaries & install
for f in /usr/bin/nx*; do echo $f; sudo ln -s $f /usr/NX/bin; done
sudo nxsetup --install

After these steps, you should be able to connect with NX client using fake GNOME session.
Raspberry Pi 2 over NX

Post is based on TiaoWiki with some updates/improvements.