I have an Ubuntu server edition running and I can SSH into it to perform various tasks. What I'd like is the ability to SSH into my server kick off a server application and then switch to another "virtual" session (with in the same SSH instance) and run client calls against the service. When I start the service its a blocking call, so I can't run client calls against it without firing up anther SSH session.
I was hoping there might be a slicker way, something like the UI does with virtual desktops.
What you want to use is screen or even better a user-friendly wrapper around screen called byobu.
Screen allows you to run multiple virtual terminal sessions in the same ssh session. A tutorial and help pages are available.
byobu is a wrapper that allows to easily open new screens with a simple function key instead of key combination from ctrl-a. It also shows a status line with all the open virtual terminals which can be named.
Another nice feature is the fact that all your screen can stay up while your ssh connection is disconnected. You just connect again via ssh and call byobu and everything is like before.
At last some screenshots of byobu.
GNU Screen is the answer you've been looking for - but it's a lot like Vi. You've got a lot of learning of commands to setup a successful Screen environment. Here's some stuff to get you started. First of all you'll want this
.screenrc
http://paste.ubuntu.com/473764/ save it on the remote server in your users home folder. Next install screen on the remote machine (sudo apt-get install screen
) Next you'll want to fire it up here are some commands for "firing up screen":screen
- This is pretty simple. It starts a new screen sessionscreen -ls
- List all active screen sessions. Yes you can have multiple terminals inside multiple screens. SO SWEET.Sample
screen -x <pid>
- This will resume a Detached screen session, IE:screen -x 16467
Once you're in a Screen (and you've employed my sample
.screenrc
file) You'll see the following along the bottom:(LOAD) 0$* bash
Which is the servers load and a list of all open "terminal tabs". Currently only one window. Type something then Press this Key Combination:
Ctrl + A
release, then pressc
.Ctrl + A
is the escape sequence. All commands are started with this combination.c
is create new tab. You'll notice the footer has(LOAD) 0-$ bash 1$* bash
which shows that there is another tab open and the active tab is number 1. You can open a maximum of 60 tabs per screen session.If you want to exit screen but keep it running use
Ctrl + A
thend
which will detach your session. Finally you can close tabs by usingCtrl + A
thenk
which will kill that tab (if it locks up) but typically you can just typeexit
as if you were in a terminal and it will close that tab.Lastly to list all windows open you can type
Ctrl + A
then"
.There are a whole slew of options available for Screen you should pour over the man file for more. There are some drawbacks. You can't use your scroll bar in Screen you have to use buffer controls to roll back, however the above is enough to get you started to see if this is a viable option. A great thing about this and something I've dealt with a lot as a System Administrator - network connectivity. If your network drops out your operations won't be lost! Since screen is running on the server. You simply need to log back in via SSH then
screen -ls
andscreen -x
back into your session.If you're using Ubuntu Server Edition
byobu
is definitely your best option. The Ubuntu Server Guide has some useful documentation.It's generally easier to learn and use than
screen
and it is installed by default.I use Emacs, so screen's default configuration makes my life difficult.
escape ^\
Try that!