Using screen to attach and detach console sessions

By on October 23rd, 2015

If you run a program in SSH, and then close out ssh you can not get back into the console.

However you can use screen to attach + detach a console.

If you have centos, run
yum -y install screen

If you have debian/ubuntu run
apt-get install screen

Once installed, screen is simple to use. Type

screen

run the command you want to run, for example

./run_server.sh

to detach run: ctrl + a + d

Once detached you can check current screens with

screen -ls

Use screen -r to attach a single screen.

On multiple screens you may see something like:

screen -ls
There are screens on:
119217.pts-3.webhosting1200 (Detached)
344074.pts-13.webhosting1200 (Detached)
825035.pts-1.webhosting1200 (Detached)
650824.downlbk (Detached)
4 Sockets in /var/run/screen/S-root.

In this case attach with the value before pts, for example

screen -r 344074

You can shorthand with screen -r 3 (assuming only one begins with the number 3).

7 Responses to “Using screen to attach and detach console sessions”

  1. Jim says:

    If the screen is detached, can I close the terminal and the process continue running?

  2. Steve says:

    so im trying to access our minecraft server (Ubuntu) from putty and for some reason i cant access the minecraft server window thing to insert commands

  3. DrHering says:

    So usually you should put your IP into putty and start it and you should get a window to type in your password and the you should have a console

  4. Mani says:

    Hi, all my screens are detached and the I’ve been seeing all the commands in progress since two days This might be because they’re all pretty memory extensive, but it also makes me wonder if they’re actually running in the background. I read that it depends on the server but I just really want to be sure.
    Thank you,

Leave a Reply