Monday, April 4, 2011

SCREEN command: Handy tool for multi-screen session and remote interaction

Screen is the Multi-Screen utility that allows the users to access the multiple screen in single SSH session that allows user to do different tasks on different screens. User doesn't require to open multiple SSH session. However, you need to learn some keyboard short-cuts.

How to start Screen?
# screen -S mySessionName

e.g screen -S rapidlinux

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


Play with above listed commands. Once you are comfortable with those commands, let's learn one more thing: REMOTE INTERACTION

Scenario: Let's say you SSHed into your client's machine. Your client want to see what commands you are running. You can do that via SCREEN :)

1. SSH into client's machine with your support user ID on client's machine.
e.g #ssh rapidsupport@client.machine

2. Run Screen command with session name
e.g #screen -S rapidsupportSession

3. You have to allow multiple user access in screen session. So, Press Ctrl + a followed by :multiuser on

4. You have to grant permission to client to access your screen session. So, Press Ctrl + a followed by :acladd clientname where clientname is the client's user ID

5. Now client can connect to your screen session using the command syntax #screen -x username/session

e.g #screen -x clientname/rapidsupportSession

6. Now your screen is shared with your client.


Done!!!!

Let's say ur client's machine is behind NAT (i.e client's machine doesn't have public IP ) and you want to provide remote support to your client. Your workstation should have public IP address to support it as ur client.

We can use Reverse SSH to achieve that.

To permit you to access your client's machine through Reverse SSH (Secure Shell protocol), client should execute the following command as root user (superuser) on his machine:

Example:

#ssh -fN -R 5099:localhost:22 rapidsupport@public-ip-address-of-rapidsupport -p 443

where, rapidsupport is an user id on your workstation

If successful, this command will set up an SSH tunnel between client's machine and rapidsupport's workstation, and will display a new command-line prompt on your server.

Note: This method of connecting is called "reverse" SSH because the connection is initiated from client's machine, not from rapidsupport.

Now, rapidsupport can SSH in client's machine using credential of client's machine.

#ssh localhost -p 5099



For more:

http://www.linux.com/archive/feed/56443
http://www.cyberciti.biz/tips/linux-screen-command-howto.html

No comments: