Linux SSH Beginners Tutorial

Here we will learn about the SSH on Linux System.

Some Basics of SSH

What is SSH

SSH (Secure SHell) is a Network protocol used for communication between two networked computer. It is different from other protocols in way that it provide security while accessing other system. Hence anyone on network will see only encrypted data and not the plain data.

Use of SSH

SSH can be used for below purpose

  1. Terminal Access
  2. Remote Command Execution
  3. File Transfer (Using SFTP or SCP protocol)
  4. Tunneling
  5. TCP Ports forwarding
  6. X11 Connection

Assigned port for SSH

Port 22 has been assigned for SSH server.

Type of SSH

SSH can be divided in two parts

  1. SSH server : Program uses SSH protocol to run service on system and wait for clients connection.
  2. SSH Client :  Program uses SSH protocol to connect to remote server.

Example of SSH Server

Example of SSH Client

How it works

SSH is based on Public Key Cryptography

What is Public Key Cryptography (PKC)

There are two keys used in PKC.

  1. Public Key
  2. Private Key:

Public Keys

Used to Encrypt Data. It can be shared publicly.

Private Keys

Used to Decrypt Data. Not supposed to be shared.

How to Create Keys

To create authentication keys ssh-keygen command can be used.

ssh-keygen -t rsa

Above command will create public and private rsa key pair.

What is Passphrase

When you create Private key as above. It will be stored in a file and any one having access to given file can misuse private key. Hence to secure private key from unauthorized access, Pass-phrase should(Not compulsory) be provided while creating private key.

Example

[email protected]:~$ ssh-keygen -t rsa

// Here asking to generate keys

Generating public/private rsa key pair.
Enter file in which to save the key (/home/hduser/.ssh/id_rsa):

// Asking for file where keys can be stored(Optional)

/home/hduser/.ssh/id_rsa already exists.
Overwrite (y/n)? y
Enter passphrase (empty for no passphrase):

// Here passphrase asked which is used to secure private key(Optional)

 
Enter same passphrase again: 
Your identification has been saved in /home/hduser/.ssh/id_rsa.

// Private key saved in this file

Your public key has been saved in /home/hduser/.ssh/id_rsa.pub.

// Public key saved in this file

The key fingerprint is:
69:67:b4:80:f6:a4:d8:e6:1b:97:4b:1c:db:dc:19:a8 [email protected]
The key's randomart image is:   
+--[ RSA 2048]----+
| . . |
| o * . |
| + = o . . |
| o = O . o |
| S E o o |
| . B . |
| . . |
| |
| |
+-----------------+
[email protected]:~$

Storing Location of Keys

Public key will be stored in ~/.ssh/authorized_keys OR ~/.ssh/id_rsa.pub. Private Key will be stored in ~/.ssh/id_rsa.

Getting Started with SSH

Here we will learn about the basic commands related to SSH. (I am using Ubuntu so some part might be different for other systems.)

Note: It is most likely that Linux system you are using have SSH already installed. If not you can use below command to install it.

sudo apt-get install openssh-server

 Start / Stop SSH Server (SSH process)/ Client (SSHD Process)

Now you have installed SSH, next step would be to start or stop these services(SSH/SSHD). You can use below command to start/ command these services.

Check status of SSH server

sudo status ssh

or

sudo service ssh status

To Start

sudo start ssh

or

sudo service ssh start

To Stop

sudo stop ssh

or

sudo service ssh stop

To Restart

sudo restart ssh

or

sudo service ssh restart

Note*: You can not restart the server if it is not in started mode. 

 

 

By | 2017-07-21T21:53:08+00:00 September 7th, 2013|Unix|0 Comments

About the Author:

Leave A Comment