Use GNU screen as login "shell"

22

11

What's the best way to have screen automatically run when you open a new shell, whether by login, xterm, or anything else?

I see the most common recommendation is to put exec screen in your regular shell's rc or login/profile file, but for, for example, tcsh, login shells run .login last, while non-login shells read .cshrc last. If I put exec screen in .cshrc, login shells won't source the .login file, and if I put it in .login, non-login shells won't run screen. I assume that there are similar issues with other shells.

wfaulk

Posted 2009-10-07T15:12:33.027

Reputation: 5 692

1

This does not answer the question, but it is worth a mention: tmux is a revolutionary step up from screen and tries to be close to keyboard compatible with screen. This page documents how to start it automatically from .bashrc.

– datashaman – 2012-11-14T17:32:45.657

Answers

19

One way is:

# if $STY is not set...
if [ -z "$STY" ]; then
    exec screen -ARR
fi

Note that this is written for bash, but should be similar for csh too. Put it to .cshrc to be executed for all shells.


Another way: You can simply set screen as your login shell in /etc/passwd itself, and put this line to your ~/.screenrc: (Fix the path, of course.)

defshell /bin/csh

But this may break programs which run the login shell defined in /etc/passwd for various commands.

(Edit: Don't forget to add screen to /etc/shells)

user1686

Posted 2009-10-07T15:12:33.027

Reputation: 283 655

1Didn't know about the STY variable before, and while looking it up in screen manual, I also found that you can execute screen with-in screen to run commands in a new window (e.g., "screen vi" will open vi in a new window, without a controlling shell).

BTW, for csh, you would put it in .login file not .cshrc, you don't want it to run for "all" shells. Samething applies to bash, put it in .profile or .bash_login, not in .bashrc. – haridsv – 2011-03-24T00:11:36.400

4

Old question, but googling for the same thing brought me here so here's a response for anyone else that stumbles onto this page.

Best thing I've found so far is byobu if your distro has it. Comes with an option to run at login and controls multiple screens at once.

You can detach and log out at one location then login to the same session at another location.

I find screen is great to use for running server processes but byobu is great for everyday things.

solbot

Posted 2009-10-07T15:12:33.027

Reputation: 41

-2

How about using chsh:

chsh /usr/bin/screen

This sets the default login shell in /etc/passwd. (you could it it there, too)

mrossi

Posted 2009-10-07T15:12:33.027

Reputation: 123

It then becomes hard to do anything with your account other than log in. Also, your sysadmin probably doesn't have screen in /etc/shells. Also, see the accepted answer. – wfaulk – 2012-08-21T13:55:50.793