SSH key
This is how you can set an ssh key so that password will not be required.
From the client enter:
$ ssh-keygen -t dsa
This will generate the public key, which is saved in the file ~/.ssh/id_dsa.pub, and the private key, saved in ~/.ssh/id_dsa. Now we copy the public key in the server by entering:
$ ssh-copy-id username@remotehost
If you use a non-standard port a little trick is necessary. We put the host address in quotation marks as
$ ssh-copy-id '-p 2222 username@remotehost'
That should work just fine! A good reference is https://help.ubuntu.com/9.04/serverguide/C/openssh-server.html and http://mikegerwitz.com/2009/10/07/ssh-copy-id-and-sshd-port/
Screen
This is how you use screen so that you can keep jobs running at a remote host even when the connection drops or you logout. First install screen on the server:
$ sudo apt-get install screen
When you log in via ssh you can initiate a screen session by typing $ screen. Now you can play around with screen using the following commands:
Ctrl+a c : creates a new terminal tab within the screen session
Ctrl+a p : goes to the previous terminal tab
Ctrl+a n : goes to the next terminal tab
Ctrl+a d : detaches the current screen so that you can come back to it later
exit : exits a terminal tab within screen or exits the screen if there is only one tab open
Within a screen you can create several terminals to interact with the host system. This is done with the command Ctrl+ c. You can also multiple screen running in the same system.
To list all screens running in the system use:
$ screen -ls
The output will be something like this:
There are screens on:
13528.pts-1.brazil (09/14/2010 09:22:08 PM) (Attached)
13496.pts-1.brazil (09/14/2010 09:09:02 PM) (Detached)
2 Sockets in /var/run/screen/S-gbezerra.
To reconnect to the detached screen type screen -r :
$ screen -r 13496.pts-1.brazil
When a screen is detached you can logout and it will still be running. The same occurs if the connection drops. Just log back in, list the active screens and reconnect to the screen you want.
You can also name the screen you create, so that it is easier to reconnect to it.
$ screen -S george
To reconnect enter:
$ screen -r george
Finally if you're running a screen in a given terminal/client and want to capture that screen at another terminal/client, but the screen has not been detatched, enter:
$ screen -rd george
this will detatch the screen and pull it into your current terminal.
A good reference for screen is http://www.howtoforge.com/linux_screen
No comments:
Post a Comment