How do I Use Multiple Screens on One Terminal over ssh session?

Most of the time GUI is not available on remote Linux system, you login over ssh and start to work, if you need to run two or three task at a time, you login over ssh two or three times. However, with screen windows manager utility you can run multiple terminals at the same time from single console login over ssh session (UNIX guru uses the term called multiplexing for this concept). Any seasoned Linux admin should be aware of this nifty tool 🙂

Install screen if it is not installed under Debian Linux

Type the following command:
# apt-get install screen

FreeBSD user can use ports to install screen

# cd /usr/ports/misc/screen
# make install clean

Login to remote server over ssh

$ ssh

(C) Start screen session. You can name your window/session (1 is name of session):
$ screen -S 1

Let us start pine mail reader on first session or window.
$ pine

(D) Next you would like to download something from ftp/http site while you are reading emails. You need to create another screen window by pressing special key combination. Press CTRL + a followed by c key (first hit CTRL+a, releases both keys and press c). As soon as you hit ‘c’ you will get new shell prompt at console. Now use wget to download belenix.iso.bz2 (Solaris live CD) from net:
$ wget

(E) But how do I switch between these two tasks?

  • Switching between windows is the specialty of screen utility. So to switch between pine and wget window (or session) press CTRL+a followed by n key (first hit CTRL+a, releases both keys and press n).
  • To list all windows use the command CTRL+a followed by ” key (first hit CTRL+a, releases both keys and press ” ).
  • To switch to window by number use the command CTRL+a followed by ‘ (first hit CTRL+a, releases both keys and press ‘ it will prompt for window number).

Common screen commands

screen command Task
Ctrl+a c Create new window
Ctrl+a k Kill the current window / session
Ctrl+a w List all windows
Ctrl+a 0-9 Go to a window numbered 0 9, use Ctrl+a w to see number
Ctrl+a Ctrl+a Toggle / switch between the current and previous window
Ctrl+a S Split terminal horizontally into regions and press Ctrl+a c to create new window there
Ctrl+a :resize Resize region
Ctrl+a :fit Fit screen size to new terminal size. You can also hit Ctrl+a F for the the same task
Ctrl+a :remove Remove / delete region. You can also hit Ctrl+a X for the same taks
Ctrl+a tab Move to next region
Ctrl+a D (Shift-d) Power detach and logout
Ctrl+a d Detach but keep shell window open
Ctrl-a Ctrl-\ Quit screen
Ctrl-a ? Display help screen i.e. display a list of commands

Suggested readings:

See screen command man page for further details:
man screen

🐧 Get the latest tutorials on Linux, Open Source & DevOps via RSS feed or Weekly email newsletter.

🐧 26 comments so far... add one

CategoryList of Unix and Linux commands
Disk space analyzersdf duf ncdu pydf
File Managementcat cp mkdir tree
FirewallAlpine Awall CentOS 8 OpenSUSE RHEL 8 Ubuntu 16.04 Ubuntu 18.04 Ubuntu 20.04
Modern utilitiesbat exa
Network UtilitiesNetHogs dig host ip nmap
OpenVPNCentOS 7 CentOS 8 Debian 10 Debian 8/9 Ubuntu 18.04 Ubuntu 20.04
Package Managerapk apt
Processes Managementbg chroot cron disown fg glances gtop jobs killall kill pidof pstree pwdx time vtop
Searchingag grep whereis which
User Informationgroups id lastcomm last lid/libuser-lid logname members users whoami who w
WireGuard VPNAlpine CentOS 8 Debian 10 Firewall Ubuntu 20.04
26 comments… add one
  • rahul Nov 8, 2008 @ 20:27

    was really nice piece of info for this newbie thnx a lot for sharing…

  • Ameya Dec 12, 2008 @ 5:52

    very helpful. Thanx. I always wanted to use screen but was not aware of how to do it.

  • Diabolic Preacher Jan 24, 2009 @ 5:58

    as usual the most interesting tools’ tutorials come from this blog and they are just easy.

    btw how do i get rid of the screens once i’m done. i found out -d detaches, but it still lists the screen. how to terminate?

  • 🐧 nixCraft Jan 24, 2009 @ 12:55

    To kill the current window hit – Ctrl-a k
    To quit screen hit – Ctrl-a Ctrl-

    I will update tutorial with frequently used commands.

  • Mar 5, 2009 @ 5:11

    I use screen all of the time. I’ve wrote about it some time ago. I find the disconnect and re-connect feature is great when trying to wrap up that last task at work. You can detach, go home, and then re-connect to see if your job is finished.

  • Jitendra Aug 24, 2009 @ 11:42

    Is there any sh script to open 20 screens using screen command in Linux? I know manually, but would like to know, using sh script. It will save my time to invoke 20 screens at a shot.

    Thanks in Advance.

    • vignesh prabhu May 11, 2010 @ 11:41

      Well you can write a .screenrc file in your home directory. Here you can configure how many screens you want to open when you start screen. This one of the most important utility I install when I am working on any server. Dont know why it is not installed by default in most of the GNU/Linux systems.

      P.S. I would ask the author to share a sample .screenrc file. A customized screen is much easier to use than to use the by-default screen.

  • Jack Sep 11, 2009 @ 14:33

    Jitendra – To invoke 20 at a time with bash:

    for i in {1..20}; do screen -dmS $i; done

  • Ganesh B S Dec 31, 2009 @ 11:35

    Here we are using “Ctr+a” command for all the options. Is there any shortcut to change “Ctr+a” to some other user defined commands like F1 (functional keys)etc.

  • Pj Jun 23, 2010 @ 21:39

    Thanks for the Tips!

  • sankar Jun 25, 2010 @ 7:23

    this is very useful to me.
    but still i have some doubts about that. how to get other system prompt via ssh in screen mode. normally we are using ssh hostname command. here how to get remote share systems using screen -x in . this is not working ……. the host will be other…..
    please give some tips..

    • Christopher Mar 11, 2015 @ 5:41

      To install ssh in your ubuntu system.
      open terminal as root user
      during installation, you must have internet connection
      #sudo apt-get install openssh-server
      after installation
      #ssh username@hostname

  • wt0fx66 Nov 25, 2010 @ 21:46

    thanks a lot! i have been seeking for this info for a long time!

  • Jonas Feb 3, 2011 @ 6:28

    Is it possible to remote logon from home via ssh, start a session in some way, and disconnect without killing the session?

    I want to logon and start a build, but I need to powerdown my client computer at home, and when I get to work, I want to be able to find my running (or finnished) build session.

    • vignesh prabhu Feb 3, 2011 @ 16:03

      Screen utility can be used for the purpose. Just ssh to the remote machine and spawn a screen session and start the build in it. Now you can also close the ssh session. The screen session will be running even after you close the ssh session.

      When you login again, you just need to run “screen -x” to reconnect to the screen session that you had spawned earlier.

      Hope it helps.

  • shailesh Mar 7, 2011 @ 15:38

    Thanks for explaining so well about screen command usage.

  • Amernath Feb 9, 2012 @ 10:11

    Very useful one!

  • Mark Mar 27, 2012 @ 14:22

    Here’s the .screenrc file I use, it will start three terminal screens within the session. I like a status line so this shows my host name, the screens and the date/time. I use a terminal with a white on black color scheme, you may want to alter these hardstatus string colors if your terminal colors are different.

    hardstatus alwayslastline
    hardstatus string ‘%{= kg}[ %{G}%H %{g}][%= %{= kg}%?%-Lw%?%{= kw}(%{= kW}%n*%f%t%?(%u)%?%{= kw})%{= kg}%?%+Lw%?%?%= %{g}][%{W}%Y-%m-%d %{W}%c %{g}]’

    # Default screens
    screen -t shell1 0
    screen -t shell2 1
    screen -t shell3 2

  • anirudh beria May 26, 2012 @ 20:08

    nice.. thnx 🙂

  • Himanshu jain Sep 18, 2012 @ 20:53

    very helpful. Thanks……………

  • Jose Tapia Mar 14, 2013 @ 21:16

    Thanks for these tips, very useful bro

  • Tasos K Apr 16, 2013 @ 15:49

    try tmux

  • prakash Jun 7, 2013 @ 6:02

    How to run multiple command on remote server using single ssh conection.

    [root@nismaster ~]# ssh “uname -a;hostname”
    root@‘s password:
    Linux nisclient2 2.6.18-164.el5 #1 SMP Tue Aug 18 15:51:54 EDT 2009 i686 i686 i386 GNU/Linux


    [root@nismaster ~]# ssh “uname -a && hostname”
    root@‘s password:
    Linux nisclient2 2.6.18-164.el5 #1 SMP Tue Aug 18 15:51:54 EDT 2009 i686 i686 i386 GNU/Linux

    • Christopher Mar 11, 2015 @ 5:44

      try it…. using double qout ” ” and semicolon :
      between two commands

  • Harneet Singh Jun 24, 2013 @ 7:54

    How do i embedd command such as ‘ctrl-a’ and ” :multiuser on ” in a script !!!
    I am trying to embedd the script in my .profile file so that everytime I login , it creates a screen session , grants user access.
    How do i embed “ctrl-a and multiuser on ” commands ?

  • abhimanyu Oct 31, 2014 @ 1:27

    the the point information

Leave a Reply

Your email address will not be published.

Use HTML <pre>...</pre> for code samples. Still have questions? Post it on our forum