Matt Kaufmann's Notes on Using Screen

NOTE: this is a work in progress!

On this page I explain what I've done to get a comfortable environment for using the linux "screen" utility to connect from my home Mac to a remote linux machine. For me it's a replacement for VNC, though since screen is text-based, one can't do graphical things like open firefox.

I mainly stay inside emacs. I've been surprised so far to find that a non-windowed emacs works well for me; thanks to Eric Smith for his help on this.

Download iTerm2

First of all, I downloaded iTerm2 onto my Mac, I think from https://www.iterm2.com. It's like the Mac's Terminal application, but seemed more promising (sorry, I forget why -- I did a lot of googling to get there). It was trivial to install on my Mac. Then after a lot of experimentation, I did the following.

Running screen

First I open iTerm2 and ssh to the remote linux machine. Very important: I supply a -e option when starting screen, telling it not to take over control-A, as shown below. Apparently that's what happens by default -- something to do with the Apple Command key. So I chose some useless key(s) for that, not that I really understand or even care to do so, and here's how I start:

screen -e '^||'

Better yet, create file ~/.screenrc and put this line in it, and then you can simply type screen:

escape ^||

To suspend ("detach") the session (kind of like quitting VNC), issue the following command, which you can even run from inside your emacs shell:

screen -d

Then later, when you want to get back to your session in the state where you left it (e.g., inside emacs if you ran "screen -d" from inside an emacs shell), run the "resume" command:

screen -r

Resuming screen After a Disconnect

Suppose you get disconnected (say, your wireless connection disappears). To reconnect, you can first detach and then resume:

screen -d
screen -r

Killing a screen process

I've been able to kill the screen process by issuing the command, exit, at the shell (not inside emacs) where is running. If anyone knows a better way to do this, please let me know!

Setting Preferences

Via drop-down menu, go to iTerm2 > Preferences; then:

Profiles > Colors
  Foreground: Black
  Background: White
Profiles > Keys > Left option key acts as +Esc
Keys > Left command key = Left option
  [Click "deny" in response to query;
   so, do not change in Mac system preferences > security-and-privacy > privacy

NOTE: I tried

  Preferences > General > Applications in terminal may access clipboard

but that didn't seem to do anything. So copying and pasting can require use of the Edit drop-down menu.

Additions to ~/.emacs file

I added the following to the end of my .emacs file (your HOSTTYPE might be different). To come up with the set-face-foreground commands, I simply put the cursor on the offending text (which often was invisible because the color was white on my white background), ran meta-x set-face-foreground, and looked at the default.

(when (equal (getenv "HOSTTYPE") "x86_64-linux")
  (require 'apropos)		      ; for apropos-symbol face, below
  (require 'message)		      ; for apropos-symbol face, below
  (require 'flyspell)		      ; for apropos-symbol face, below
  (require 'erc)		      ; for apropos-symbol face, below
  (require 'rmail)		      ; for apropos-symbol face, below
  (require 'font-latex)		      ; for apropos-symbol face, below
  (normal-erase-is-backspace-mode -1)
  (setq electric-indent-mode nil)
  (set-face-foreground 'comint-highlight-input "blue")
  (set-face-foreground 'apropos-symbol "blue")
  (set-face-foreground 'message-header-to "blue")
  (set-face-foreground 'flyspell-duplicate "blue")
  (set-face-foreground 'font-lock-string-face "blue")
  (set-face-foreground 'erc-nick-default-face "black")
  (set-face-foreground 'bold "blue")
  (set-face-foreground 'bold-italic "blue")
  (set-face-foreground 'buffer-menu-buffer "blue")
  (set-face-foreground 'rmail-highlight "black")
  (set-face-background 'rmail-highlight "yellow")
  (set-face-background 'region "yellow")
  (set-face-foreground 'font-latex-sedate-face "blue")
  (set-face-foreground 'font-latex-sectioning-2-face "blue")
  (set-face-foreground 'font-latex-bold-face "blue")
  (set-face-background 'isearch "yellow"))

Conclusion

This is hardly a conclusion! I expect that this page will evolve over time. Dead-trivial suggestions are welcomed — but I don't want to spend any more time than I have to messing with this stuff!