SSH in Linux

SSH in Linux

Secure Shell - Remote Login

What is SSH?

The Secure Shell Protocol (SSH) is a cryptographic network protocol that allows network services to be operated safely over an unsecured network.
Remote login and command-line execution are two of its most noteworthy applications.
SSH apps use a client-server architecture to connect an SSH client to an SSH server.

Difference Between Telnet & SSH

  1. Telnet :

    1. It is a remote access protocol

    2. It is an unsecured remote access protocol

    3. It uses port no 23

    4. Transfer the data in plain text

    5. Not recommended for public networks, but used for private networks.

  2. SSH :

    1. It is a remote access protocol

    2. It is a secured remote access protocol

    3. It uses port no 22

    4. Transfer the data in an encrypted format

    5. Recommended for public networks

SSH server pre-request :

  1. SSH package installed

  2. SSH status should be active --> systemctl status sshd

  3. Check 22 port is open --> netstat -tunlp|grep 22

  4. Check if service is enabled --> systemctl enable sshd

  5. Check if service is started / active --> systemctl start sshd

How to know if any system is accessed remotely?
who - Displays information about all users currently on the local system.
finger - Find information about computer users.

Where the keys are stored on the server side?
/etc/ssh
Where the keys are stored on the client side?
/<homedirectory>/.ssh/

Server Configuration File :
The sshd_config file specifies the locations of one or more host key files (mandatory) and the location of authorized_keys files for users.

  1. Location of sshd_config --> /etc/ssh/sshd_config

  2. The root is initially disabled for security reasons.

  3. Max session --> Numbers of connections can be established remotely.

  4. Allow users --> Users you want to allow connections.

  5. Deny users --> Users you want to deny connections.

How to control the machine to establish the connection remotely??
/etc/host.deny
e.g.
sshd : 172.10.21.10 --> Specfic IP
sshd : 172.25.0.0/255 --> Specfic network
sshd ALL --> No one can establish a connection remotely

If ssh is not working what can be the possible reasons?
Troubleshooting :

  1. Service OFF

  2. Password wrong

  3. Token - NO

  4. Max session

  5. Deny user

  6. Public Authentication

  7. Port Closed

  8. N/W denial

  9. Root user NO PERMIT

How to connect to the machine remotely?

#ssh <username>@<IP/hostname>
ssh ansible@172.12.2.4