September 30, 2017

SSH : Remote host identification has changed

So you have recently connected to a remote Server A via ssh.

The Server A's key is then saved into a file in your local PC, typically $HOME/.ssh/known_hosts

It may looks like this :

serverA ecdsa-sha2-nistp256 AAAAE2VjZHNhLXasdasdasdmlzdHAyNTYAAAAIbm
lzddddHAyNTYAAABBBNrIVAhYMcnUasdasdsdoMv7gtf8nMHghgYzVcdddkzbDM79C
81qswhYdd8L9VX+pNjg+asdasdasdasdasdasdxgooCk=

Imagine, suddenly, the remote Server A changed their key.
As a result, the key you have in your local PC, inside known_hosts becomes invalid.

The moment you try to ssh to Server A again, you will be prompted with :

@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
@    WARNING: REMOTE HOST IDENTIFICATION HAS CHANGED!     @
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
IT IS POSSIBLE THAT SOMEONE IS DOING SOMETHING NASTY!
Someone could be eavesdropping on you right now (man-in-the-middle attack)!
It is also possible that the RSA host key has just been changed.
The fingerprint for the RSA key sent by the remote host is
a7:a8:f2:97:94:33:58:b7:9d:bc:e0:a6:6b:f7:0a:29.
Please contact your system administrator.
Add correct host key in /home/ramesh/.ssh/known_hosts to get rid of this message.
Offending key in /home/ramesh/.ssh/known_hosts: 6
Permission denied (publickey,password).
The solution is to edit the file known_hosts and remove the existing key of Server A,
using your preferred text editor i.e. vi or vim or nano or notepad

When you try to ssh to Server A again, the new key of Server A will be saved into 
your local file known_hosts.

September 25, 2017

SSH SCP with Java

Good library to use is Java Secure Channel (JSch) from http://www.jcraft.com/jsch

Java doc : http://epaul.github.io/jsch-documentation/simple.javadoc/

Source code : https://github.com/ePaul/jsch-documentation

September 14, 2017

Undo bad commit

Sometimes when you did commit like below, you have forgoten where you are and accidentally committed every local changes under the current folder tree, including some that you don't want to. Urrgh!

Example : svn commit -m 'blabla'

For example, above commit results in revision 101.

You want to get back the repo to what was in 100.

You run :
1. Go to the same folder when you did the commit

2. Merge to the previous revision i.e. 100
svn merge -c -100 .

3. Check what changes this one will take place
svn stat

4. Commit
svn commit -m 'sorry Im so dumb before but I learned now'

Now you have the new revision i.e. 102 is now back to what was in 100

September 5, 2017

MySQL : Conditional If-else when selection returns empty result set

I am still very new to MySQL or SQL in general. So, this is kind of new.

I need to run a select statement and if that select statement return nothing, I would like to run another different select statement :

IF EXISTS (select something from TABLE_A) THEN                                         select something from TABLE_A;                                                 
ELSE
    select something from TABLE_B;
END IF;
More from StackOverflow :

IF NOT EXISTS (SELECT ...)
BEGIN
  INSERT ...
END
And with more control :

IF EXISTS (SELECT ...)
BEGIN
  PRINT 'Do nothing.';
END
ELSE
BEGIN
  INSERT ...
END