Difference between revisions of "WorkingOnServers/JFBsWorkFlow"

From mn/geo/geoit
Jump to: navigation, search
Line 5: Line 5:
 
==Firs Things First==
 
==Firs Things First==
 
Let's first take care of a few definitions:
 
Let's first take care of a few definitions:
;client: your local machine/computer that is sitting in front of you
+
;client / local: your local machine/computer that is sitting in front of you
;server / host: the machine/computer that you are connecting to
+
;host / remote: the machine/computer that you are connecting to
 
;display: the monitor in front of you
 
;display: the monitor in front of you
  
Line 28: Line 28:
  
 
Once connected to the host machine, you may want to invoke [http://www.gnu.org/software/screen/screen.html screen] if you're running a big job. You can also use 'nohup' of course.
 
Once connected to the host machine, you may want to invoke [http://www.gnu.org/software/screen/screen.html screen] if you're running a big job. You can also use 'nohup' of course.
 +
 +
====Connecting to the Servers====
 +
In order to make connecting to the servers seemless, it is highly recommended to set up ssh keys. It takes a little bit of time and configuring, but once completed, passwordless login is a breeze, and you'll find using commands such as scp, sshfs, and ssh to be painless. In terms of the choice of ssh utilities, that will largely depend on your OS. For linux, it's built in, but for Windows you'll need to download a client program such as Putty.
 +
 +
Here we'll work through:
 +
# Setting up your ssh keys for passwordless login
 +
# Setting up your ssh connection to forward X displays
 +
 +
=====SSH Keys=====
 +
Shamelessly take from [http://www.thegeekstuff.com/2008/11/3-steps-to-perform-ssh-login-without-password-using-ssh-keygen-ssh-copy-id/ geekstuff], [http://blogs.translucentcode.org/mick/archives/000230.html mick], and [http://www.cyberciti.biz/tips/linux-multiple-ssh-key-based-authentication.html unixcraft]
 +
 +
'''Goal'''
 +
You want to use Linux and OpenSSH to automize your tasks. Therefore you need an automatic login from userA@local to userB@host (note userA and userB may or may not be the same user). You don't want to enter any passwords, because you want to call ssh from a within a shell script.
 +
 +
First log in to your machine as userA@local and generate a pair of authentication keys:
 +
 +
'''NOTE''' Do not enter a passphrase to simplify things (it is less secure, but it makes things less complicated -- if you do want a passphrase, see the notes below).
 +
<pre>
 +
usera@loca:~> ssh-keygen -t rsa
 +
Generating public/private rsa key pair.
 +
Enter file in which to save the key (/home/a/.ssh/id_rsa):
 +
Created directory '/home/a/.ssh'.
 +
Enter passphrase (empty for no passphrase):
 +
Enter same passphrase again:
 +
Your identification has been saved in /home/usera/.ssh/id_rsa.
 +
Your public key has been saved in /home/usera/.ssh/id_rsa.pub.
 +
The key fingerprint is:
 +
3e:4f:05:79:3a:9f:96:7c:3b:ad:e9:58:37:bc:37:e4 a@A
 +
</pre>
 +
Now use ssh to create a directory ~/.ssh as user b on B. (The directory may already exist, which is fine):
 +
<pre>
 +
usera@local:~> ssh userb@remote mkdir -p .ssh
 +
userb@remote's password:
 +
 +
</pre>
 +
Finally append usera's new public key to userb@remote:.ssh/authorized_keys and enter userb's password one last time:
 +
<pre>
 +
usera@local:~> cat .ssh/id_rsa.pub | ssh userb@remote 'cat >> .ssh/authorized_keys'
 +
userb@remote's password:
 +
</pre>
 +
 +
From now on you can log into remote as userb from local as usera without password:
 +
<pre>
 +
usera@local:~> ssh userb@remote
 +
</pre>
 +
 +
Depending on your version of SSH you ''will likely'' also have to do the following changes:
 +
 +
* Put the public key in .ssh/authorized_keys2
 +
* Change the permissions of .ssh to 700
 +
* Change the permissions of .ssh/authorized_keys2 to 640
 +
 +
'''If you use a passphrase for the ssh key'''

Revision as of 10:43, 15 September 2011

This is a tip contributed by Jfb 15:34, 14 September 2011 (CEST)

I have put this guide together for reference, but also to help anyone who is intending to work on the NILU servers. It is mostly specific to connecting to the machines from a linux box, but there may be alternatives for some of the tools I am discussing here. If I know of them, I will try to make reference as appropriate.

Firs Things First

Let's first take care of a few definitions:

client / local
your local machine/computer that is sitting in front of you
host / remote
the machine/computer that you are connecting to
display
the monitor in front of you

The Client Environment

List of software I use regularly:


Editors

Critical to software programming and working on servers is to have a good editor. I dare not make strong recommendations here, but would suggest that you find one you are comfortable working with. Key features I look for:

  • syntax highlighting
  • project browser (e.g. a panel that displays project resources next to your editor)
  • an object browser (this is getting toward an IDE, but many text editors also have this capacity)

On windows [:notepad++] is a good option. For Linux there are many to choose from, and if you're using linux, you probably have a favorite ;)

Shell / Terminal

For linux I think terminator is a terrific environment for working with the command line.

Once connected to the host machine, you may want to invoke screen if you're running a big job. You can also use 'nohup' of course.

Connecting to the Servers

In order to make connecting to the servers seemless, it is highly recommended to set up ssh keys. It takes a little bit of time and configuring, but once completed, passwordless login is a breeze, and you'll find using commands such as scp, sshfs, and ssh to be painless. In terms of the choice of ssh utilities, that will largely depend on your OS. For linux, it's built in, but for Windows you'll need to download a client program such as Putty.

Here we'll work through:

  1. Setting up your ssh keys for passwordless login
  2. Setting up your ssh connection to forward X displays
SSH Keys

Shamelessly take from geekstuff, mick, and unixcraft

Goal You want to use Linux and OpenSSH to automize your tasks. Therefore you need an automatic login from userA@local to userB@host (note userA and userB may or may not be the same user). You don't want to enter any passwords, because you want to call ssh from a within a shell script.

First log in to your machine as userA@local and generate a pair of authentication keys:

NOTE Do not enter a passphrase to simplify things (it is less secure, but it makes things less complicated -- if you do want a passphrase, see the notes below).

usera@loca:~> ssh-keygen -t rsa
Generating public/private rsa key pair.
Enter file in which to save the key (/home/a/.ssh/id_rsa): 
Created directory '/home/a/.ssh'.
Enter passphrase (empty for no passphrase): 
Enter same passphrase again: 
Your identification has been saved in /home/usera/.ssh/id_rsa.
Your public key has been saved in /home/usera/.ssh/id_rsa.pub.
The key fingerprint is:
3e:4f:05:79:3a:9f:96:7c:3b:ad:e9:58:37:bc:37:e4 a@A

Now use ssh to create a directory ~/.ssh as user b on B. (The directory may already exist, which is fine):

usera@local:~> ssh userb@remote mkdir -p .ssh
userb@remote's password: 

Finally append usera's new public key to userb@remote:.ssh/authorized_keys and enter userb's password one last time:

usera@local:~> cat .ssh/id_rsa.pub | ssh userb@remote 'cat >> .ssh/authorized_keys'
userb@remote's password: 

From now on you can log into remote as userb from local as usera without password:

usera@local:~> ssh userb@remote

Depending on your version of SSH you will likely also have to do the following changes:

  • Put the public key in .ssh/authorized_keys2
  • Change the permissions of .ssh to 700
  • Change the permissions of .ssh/authorized_keys2 to 640

If you use a passphrase for the ssh key