Showing posts with label ssh. Show all posts
Showing posts with label ssh. Show all posts

Monday, October 10, 2011

Generate SSH Key on Linux for Android

If you need to generate an SSH key pair on your Linux PC for your Android device (i.e. ConnectBot or AndFTP), here's how I did it.

ssh-keygen -b 2048 -C Droid2 -t rsa -f id_rsa_droid2

Then the private key only needs to reside on the Android device (then import into software that needs it), and the contents of the public key need to be added onto the .ssh/authorized_keys file on every remote host you desire to ssh into from the Android device. One way is to get the public key file on the remote host, then enter

cat id_rsa_droid2.pub >> .ssh/authorized_keys

(the ">>" says to append the contents of id_rsa_droid2.pub to the end of the authorized_keys file)

If I find a better way—for example generating an OpenSSH-compatible keypair on the actual Android device—I'll post it.

Saturday, November 20, 2010

SSH Host Key Error

When trying to ssh into a server you may get the following error:
@@@@@@@@@@@@@@@@@@@@@@@@@@@@
@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
5b:9c:15:52:a1:ce:19:80:3b:ad:4b:b2:31:ad:d5:4c.
Please contact your system administrator.
Add correct host key in /home/user/.ssh/known_hosts to get rid of this message.
Offending key in /home/user/.ssh/known_hosts:1
RSA host key for ras.mydomain.com has changed and you have requested strict checking.
Host key verification failed.

If you have reinstalled Linux with OpenSSH, you will get the above error. To confirm the fingerprint of the server, login to it directly if possible and execute

ssh-keygen -l -f /etc/ssh/ssh_host_rsa_key.pub

(To confirm fingerprint of other host keys use:

ssh-keygen -l -f /etc/ssh/ssh_host_dsa_key.pub
ssh-keygen -l -f /etc/ssh/ssh_host_key.pub


To get rid of this problem (if you are certain it it NOT due to an actual security breach):

Remove The Offending Key

Use the -R option to removes all keys belonging to hostname from a known_hosts file. This option is useful to delete hashed hosts. If your remote hostname is server.example.com, enter:

$ ssh-keygen -R {server.name.com}

$ ssh-keygen -R {ssh.server.ip.address}

$ ssh-keygen -R server.example.com


Sample output:
/home/robert/.ssh/known_hosts updated.
Original contents retained as /home/vivek/.ssh/known_hosts.old
Now, you can connect to the host without a problem.

Friday, February 12, 2010

Login to FreeNAS via Passwordless SSH - GNU/Linux

I found this solution on the FreeNAS forums. It's not very straightforward, in my opinion, to setup SSH passwordless login on FreeNAS.

Taken from FreeNAS forums:

What you need to do to customize your server for passwordless authentication:
  1. From WebGUI|Advanced|Execute command or shell
    1. protect the /mnt directory by setting the mode to 755(we don't want users to write on /mnt, that can fill up the RAM disk and crash the system.

      You must change the mod as startup command, after each reboot.

      Code:

      chmod 755 /mnt
    2. For your safety change the mode for each mount, or at least one "mount".

      Code:

      chmod 755 /mnt/mount
    3. Create the user(A) home directory /mnt/mount/userA

      Code:

      mkdir /mnt/mount/userAdir
    4. Make userA the owner of his home directory

      Code:

      chown userA /mnt/mount/userAdir
    5. Secure userA home directory

      Code:

      chmod 700 /mnt/mount/userAdir
  2. Set userA home directory on WebGUI|Access|Users|Edit|Home directory to point to /mnt/mount/userAdir

  3. From your remote client(ssh/PuTTy)
    1. Check if home directory is set corectly for userA. The output should be /mnt/mount/userAdir

      Code:

      ssh -p 22 userA@FreeNASip 'pwd'
    2. Create the .ssh directory

      Code:

      ssh -p 22 userA@FreeNASip 'mkdir .ssh'
    3. Upload your id_rsa.pub or id_dsa.pub to remote .ssh directory.

      Code:

      cat id_rsa.pub | ssh -p 22 userA@FreeNASip 'cat >> .ssh/authorized_keys'
    4. Change the .ssh dir mode

      Code:

      ssh -p 22 userA@FreeNASip 'chmod -R 700 ~/.ssh'
  4. Now try to login passwordless.