Install SSH (Ubuntu, Kodibuntu), Connect with PuTTy (Windows)

Install SSH (Ubuntu, Kodibuntu), Connect with PuTTy (Windows)

WHAT IS SSH and PuTTy?

SSH is a server that will grant access to your computer remotely without any graphical interface. In other words, you will be able to connect to your linux computer with any other computers in your network via a terminal. Accessing your ssh from internet is not really recommended unless your secure your connection with a key as shown below.
PuTTy is a utility that mimic Linux terminal. If you want to remotely connect to Linux with a Linux computer, you won’t need PuTTy since you already have a Linux terminal. In Windows, there is no such things and this is why you will need something like PuTTy to get the job done.

Here is an example of PuTTy inside Windows connected to a Linux shell (Ubuntu):

ssh-putty


INSTALL SSH (Ubuntu / Kodibuntu):

Kodibuntu comes with SSH server already installed out of the box, so you can skip #1.

  1. Open a terminal and type:
    sudo apt-get install openssh-server
  2. create a back of your configuration file:
    sudo cp /etc/ssh/sshd_config /etc/ssh/sshd_config.original
  3. To edit the configuration of your SSH server, open this file with sudo privilege:
    sudo nano /etc/ssh/sshd_config
  4. You can leave everything to default and it will work well.
  5. Read the Manual of SSH for all the command references and descriptions: man sshd_config or you can find online here: http://www.openssh.com/cgi-bin/man.cgi/OpenBSD-current/man5/sshd_config.5?&manpath=OpenBSD-current&query=sshd_config
  6. Once you’ve finish the configuration just restart the SSH Server with this command:
    sudo /etc/init.d/ssh restart

 


INSTALL PuTTy (Windows):

Dowload the last windows build of PuTTy here PuTTy.exe:
http://www.chiark.greenend.org.uk/~sgtatham/putty/download.html

  1. There is no installer just Launch it and enter the local ip address of the computer you want to connect to.
  2. Click Open:
    ssh_first_connect
  3. A terminal will appear. Just enter the remote computer login information and that’s it (You can use any of your linux users to remotely login). If no firewall is blocking you, you will be connected:
    ssh-putty

SECURE YOUR SSH/PuTTy Connection with a 2048bit RSA Key:

Connecting to your a SSH with a key will enhance the security by getting rid of the normal username/password login. You will be protected against brute force attack and in the meantime your ssh will be a little bit more secure.

Creating SSH Keys in windows:

  1. You will need another software from the same organisation: PuTTyGen.exehttp://www.chiark.greenend.org.uk/~sgtatham/putty/download.html
  2. Hit Generate and randomly move your mouse in the blank area while the bar progress: securessh1
  3. Enter the key-phrase twice
  4. Save private (private_rsa2048_192.168.2.11.ppk) and public key (public_rsa2048_192.168.2.11.txt) in a folder you will remember. Keep this window open.securessh2
  5. Open PuTTy.exe, go under Connection->SSH->Auth and browse for your private keysecuressh3
  6. You save this as a preset in Session: securessh4
  7. Next click the Open Button
  8. A terminal window will appear and you will be prompt for username. Enter the linux username you want to connect with. The server will reject the key we installed in putty and this is normal. We didn’t install it yet.ssh_refusekey
  9. Create a folder in your home directory:
    mkdir ~/.ssh
  10. Change permission so just user can write and read:
    chmod 700 ~/.ssh
  11. Create a key file and Edit it:
    nano ~/.ssh/authorized_keys2
  12. Copy the key from the PuttyKey Generator and paste it into the file:copy_key
  13. Save your file by quitting with Ctrl+X and hit Y for Yes
  14. Change permission for ready-only by this user:
    chmod 400 ~/.ssh/authorized_keys2
  15. Re-open PuttY and load your config with the private key set in the parameters (Step 5). Now, you will be prompt for the passphrase you’ve entered in the Putty Key Generator:ssh_secure_connection
  16. Get rid of the old username/password method by editing your ssh config:
    sudo nano /etc/ssh/sshd_config
  17. Add / Modifiy these lines. It will disable password login and enable rsa and public key login:
    #Disable Password:
    PasswordAuthentication no
    
    #Enable public / rsa keys:
    #(it should already be like this by default)
    RSAAuthentication yes
    PubkeyAuthentication yes
    
  18. Restart SSH:
    sudo restart ssh

Stop Asking for Passphrase and Login only with Username:

You can set an automatic login with an agent that will inject the passphrase into PuTTy

  1. You will need another software from the same organisation: pageant.exehttp://www.chiark.greenend.org.uk/~sgtatham/putty/download.html
  2. Launch pageant.exe. It will add an icon to the systray. Right-Click on it and choose View Keyspageant
  3. Click on Add Key. Browse for your private key (private_rsa2048_192.168.2.11.ppk). You will be prompt for a passphrase: enter the one you typed in the PuTTy Key Generator and hit OK passphrase
  4. Close Window and open PuTTy
  5. Log in with your saved Session, enter your username and you should see something like this:agentlogin

—————————-
Ressource used:
– https://help.ubuntu.com/10.04/serverguide/openssh-server.html
http://www.howtoforge.com/ssh_key_based_logins_putty_p2
—————————-