czwartek, 16 lipca 2015

ssh and hosts configuration to make tunnelling and logging to server easier

Content of ".../home/user/.ssh/config" file:
### Default settings
Host *
    ServerAliveInterval 180
    ServerAliveCountMax 999
    AddressFamily inet

### server config example
Host appdev
 Hostname appdev.server.com
 Port 22
 User loginUserName
 IdentityFile ~/.ssh/MyPrivateKey.openssh


### Tunnels configuration example. Start with ssh -f -N tunnels
Host tunnels
 Hostname appdev.server.com
 Port 22
 User loginUserName
 IdentityFile ~/.ssh/MyPrivateKey.openssh
 
 LocalForward service1host_local:80 service1host_real:80
 LocalForward service2host_local:80 service2host_real:80
        ...

Things to remember:


1) in hosts file there must be mapping for serviceXhost_local to unique localhost IP:


127.0.0.1  service1host_local 
127.0.0.2  service2host_local 
...

2) private key must be in openssh format (puttygen will do conversion)

3) remove password from private key to skip the prompt eveytime (puttygen will do conversion). But thats kind of security breach

See also:
http://nerderati.com/2011/03/17/simplify-your-life-with-an-ssh-config-file/

Script for checking installed software versions on remote servers

serverShortcut - server connection name from .ssh/config
#!/bin/sh

### params: (1) app&server identifier
### params: (2) server and path to pom.properties file of an app to check
function printInfoFor {
 # delete properties file
 rm -f $1.properties
 
 # scp remote file to current dir
 scp $2 $1.properties
 
 # 'execute' properties file, properties will be available as variables
 . $1.properties
  
 # print required infos
 echo "$1 -> $version"
}  

###### TST
printInfoFor maApp_TST     serverShortcut:/opt/app/tomcat/current/webapps/app-api/META-INF/maven/xxxxx/pom.properties