Showing posts with label Ubuntu. Show all posts
Showing posts with label Ubuntu. Show all posts

Friday, December 12, 2014

Using Git With Multiple SSH Keys and Accounts

Generating SSH keys for GitHub

Here are github account and work account.

  • GitHub:
    SSH Key: github_id_rsa
    Account: oopsmonk

  • Work:
    SSH Key: work_id_rsa
    Account: SamChen

Add SSH config File

Modify ~/.ssh/config

# Default github
Host github.com
    HostName github.com
    PreferredAuthentications publickey
    IdentityFile ~/.ssh/github_id_rsa

# Work git server
Host work.gitserver.com
    HostName work.gitserver.com
    PreferredAuthentications publickey
    IdentityFile ~/.ssh/work_id_rsa

Git Repository Configuation

  • GitHub Project:

    $ git clone https://github.com/abc/projectA.git  
    $ cd projectA
    #github account
    $ git config user.name "oopsmonk"
    $ git config user.email "oopsmonk@example.com.tw"
  • Working Project:

    $ git clone https://work.com.tw/repo/projectW.git  
    $ cd projectW
    #working account
    $ git config user.name "SamChen"
    $ git config user.email "SamChen@example.com.tw"

Now you can deal with git repositories using different accounts.

(Additional) Using ssh-agent to access GitHub without password

Check key list

# No ssh-agent running 
$ ssh-add -l
Could not open a connection to your authentication agent.
$  

Enable ssh-agent (Ubuntu12.04):

#enable ssh-agent
$ eval `ssh-agent -s`

#add keys to agent
$ cd ~/.ssh
$ ssh-add work_id_rsa github_id_rsa
Identity added: work_id_rsa (work_id_rsa)
Identity added: github_id_rsa (github_id_rsa)

#list added keys
$ ssh-add -L

#delete keys in agent  
$ ssh-add -D

Now you can commit modifications to git repository without password.

Reference:
Understanding ssh-agent and ssh-add
How can I run ssh-add automatically, without password prompt?

Friday, July 5, 2013

Redirect and Save iptables on Ubuntu 12.04

Redirect port 8080 to 80

sudo iptables -t nat -A PREROUTING -p tcp --dport 80 -j REDIRECT --to-port 8080  

Check iptables setting

sudo iptables -t nat -L  

Save configure to iptables.rules

sudo iptables-save > /etc/iptables.rules  

Save Solution #1

Configre /etc/network/interfaces

iface eth0 inet dhcp  
    pre-up iptables-restore < /etc/iptables.rules  

Save Solution #2

Configure /etc/network/if-pre-up.d/iptablesload

#!/bin/sh
iptables-restore < /etc/iptables.rules
exit 0

Configure /etc/network/if-post-down.d/iptablessave

#!/bin/sh
iptables-save -c > /etc/iptables.rules
if [ -f /etc/iptables.downrules ]; then
    iptables-restore < /etc/iptables.downrules
fi
exit 0

Change permissions

sudo chmod +x /etc/network/if-post-down.d/iptablessave  
sudo chmod +x /etc/network/if-pre-up.d/iptablesload  

Reference:
Tomcat: redirecting traffic from port 8080 to 80 using iptables
IptablesHowTo

Wednesday, June 19, 2013

Install JDK1.4.2(32bit) on Ubuntu 12.04 LTS(64bit)

Here is an error occurred if installed directly:
install.sfx.XXX: not found

Solution:

  • install g++-mltilib and JDK

    $ sudo apt-get install g++-multilib  
    $ chmod +x j2sdk-1_4_2_19-linux-i586.bin  
    $ ./j2sdk-1_4_2_19-linux-i586.bin
    .....
    Do you agree to the above license terms? [yes or no]
    yes
    Unpacking...
    Checksumming...
    0
    0
    Extracting...
    UnZipSFX 5.40 of 28 November 1998, by Info-ZIP (Zip-Bugs@lists.wku.edu).
       creating: j2sdk1.4.2_19/
       creating: j2sdk1.4.2_19/jre/
       creating: j2sdk1.4.2_19/jre/bin/
      inflating: j2sdk1.4.2_19/jre/bin/java
      inflating: j2sdk1.4.2_19/jre/bin/keytool
      inflating: j2sdk1.4.2_19/jre/bin/policytool
    ....
    Creating j2sdk1.4.2_19/lib/tools.jar
    Creating j2sdk1.4.2_19/jre/lib/rt.jar
    Creating j2sdk1.4.2_19/jre/lib/jsse.jar
    Creating j2sdk1.4.2_19/jre/lib/charsets.jar
    Creating j2sdk1.4.2_19/jre/lib/ext/localedata.jar
    Creating j2sdk1.4.2_19/jre/lib/plugin.jar
    Creating j2sdk1.4.2_19/jre/javaws/javaws.jar
    Done.  
    $ sudo mkdir -p /usr/lib/jvm  
    $ sudo mv j2sdk1.4.2_19 /usr/lib/jvm/java-1.4.2_19
  • Java environment configuration.

    $ wget http://webupd8.googlecode.com/files/update-java-0.5b  
    $ chmod +x update-java-0.5b
    $ sudo ./update-java-0.5b  

    Select java-1.4.2_19

    Check java version

    $ java -version
    java version "1.4.2_19"
    Java(TM) 2 Runtime Environment, Standard Edition (build 1.4.2_19-b04)
    Java HotSpot(TM) Client VM (build 1.4.2_19-b04, mixed mode)