Monday, 4 March 2013

Using linux screen to remotely work on a linux server

The linux screen command can be used to remotely work on a linux server, for example, if you connect from a Mac laptop at home to a linux server at work.

The .screenrc file in your home directory of your linux server controls your settings for 'screen'. I have my .screenrc in the home directory of my remote linux server like this (thanks to my colleague Daria Gordon for this):
shell /bin/tcsh
autodetach on
caption always
escape ^Jj
hardstatus alwayslastline "%{rw}%H %{yk}%D %d %M %Y %{gk}%c %{wk}%?%-Lw%?%{bw}%n*%f %t%?(%u)%?%{wk}%?%+Lw%?"
scrollback 999999

To do this log in to your remote linux server, eg. :
% ssh farm2-head3
Then start a 'screen' session:
% screen -RD
This gives me the following view:

The text at the bottom of the screen that is highlighted in blue tells me that I am in window '0', the default window.
To make a new window within screen, I can type:
% CTRL-j + c
I then see that I in window '1' (highlighted in blue):

I can then move back into window '0' by typing:
% CTRL-j + 0
I can then move back into window '1' by typing:
% CTRL-j + 1

Or to go to the next window, type:
% CTRL-j + space-bar

To 'detach' from the screen session on this linux server (farm2-head3) (ie. temporarily exit from it), you can type:
% CTRL-j + d

I can then go to another computer, log into farm2-head3, and start the screen session again by typing:
% screen -RD

Note that if you can have several screen sessions, eg. I could have a different one on farm2-head2 than the one on farm2-head3.

To end a screen session completely (so that you can't log back in using 'screen -RD'), type when you are in the screen session:
% exit

Thanks to Daria Gordon for showing me how to use screen.

 [Note later (17 June 2019): found that on farm4 I needed to change 'shell /usr/local/bin/bash to /bin/bash in ~alc/.screenrc to get screen to work.]

No comments: