Linux Insider

SARTHAK SHINDESARTHAK SHINDE
5 min read

Hey✋, What's up guys, Sarthak Shinde here, Welcome back to another blog. In this blog, I will cover all the points related to Linux Workshop carried out byPranav Jambare at Dr.Babasaheb Ambedkar Technological University, Lonere. Those who didn't check my previous blogs please check it out first.

On the fourth day of the workshop following topics were covered.

  • SSH

  • Find and Locate

  • Password-Less SSH

SSH

  • SSH stands for 'Secure Shell Protocol'.

  • It is a widely used network protocol that provides a secure way to access remote servers and computers.

  • It allows network services to be operated safely over an unsecured network.

  • It is a secured remote access protocol and works on port no 22.

  • It transfers the data in an encrypted format.

  • The SSH command provides a secure encrypted connection between two hosts over an insecure network.

An SSH key relies upon the use of two related keys that together create a key pair that is used as the secure access credential:

  1. Public Key: The Public Key can be shared freely with any SSH server to which the user wishes to connect.

  2. Private Key: The private key is secret, known only to the user, and should be encrypted and stored safely.

Creating an SSH Connection:

  1. To run the SSH command these two packages must be installed:
  • openssh -server

  • openssh -client

  1. To install package following command is used:
#Syntax:
yum install [pacakagename] -y
#To install server package:
yum install openssh -server -y
#To install client package:
yum install openssh -client -y
  1. To Check port whether it is active or not:
nestat -tunlp|grep 22
  1. To Check service status: It can be in restart, start and stop state.
#Syntax
systemctl status <servicename>
#Command
systemctl status sshd
#To restart service
systemctl restart sshd
#To start service
systemctl start sshd
#To stop service
systemctl stop sshd
  1. Syntax and command to connect:
#Syntax:
ssh [username]@[IP]
#Command
ssh sarthak@192.168.1.4

Connecting different servers by allowing or denying users:

First, we can go through the configuration file of ssh.

vim /etc/ssh/sshd_config
#Syntax
AllowUsers <username>
DenyUsers <username>

#Command
AllowUsers sarthak
DenyUsers heyguys

Connecting different servers by allowing or denying networks:

#To allow any server
vim /etc/host.allow
#To allow access from the specific IP address:
#Syntax:
<servicename>: <IP>
#Example:
sshd: 192.168.1.6

#To deny any server
vim /etc/host.deny
#To deny access from the specific IP address:
#Syntax:
<servicename>: <IP>
#Example:
sshd: 192.168.1.6

Find Command:

  • The 'Find' command is a versatile tool for searching files and directories based on various criteria.

  • It allows you to search for files, folders, names, creation dates, modification dates, owners, and permissions.

  • It traverses the specified directory hierarchy recursively and performs a search based on the given expressions.

  • The find command helps us to find a particular file within a directory.

  • It scans the file system dynamically.

  • It produces real-time outputs.

      #Syntax:
       find <path> <expression>
       find [path] [what to find] [-options] [file/directory name]
    

    Options

  • Find the files by their name -name .

#Syntax:
find <location> -name <filename>
#Example:
find /home -name sampleFile
  • Find the files owned by the specific user -user .
#Syntax:
find <path> -user <username>

#Example:
find / -user testuser
  • Find files and delete them.
#Syntax:
find <path> -name <filename> -exec rm -rf {} \;

#Example:
find /tmp -name sampleFile -exec rm -rf {} \;
  • Find the directories or files.
#For Directories:
#Syntax:
find <path> -type d 
#Example:
find / -type d

#For Files:
#Syntax:
find <path> -type f
#Example:
find /home -type f
  • Find files with specific permission
#Syntax:
find <path> -perm <permissionNo> 
#Example:
find /tmp -perm 755

Locate

  • The 'Locate'command provides a faster way to search for files by using a prebuilt database of filenames.

  • It regularly updates the database for efficient searching.

  • To use locate command we have to update the database first.

  • Locate command is used in the database and the database contains a number of inodes.

  • The locate tool works better and faster than the find command counterpart.

  • It is faster than the find command but may not provide real-time results.

  • It is considered to be a static searching tool.

Database Updating:

#Syntax:
updatedb

Syntax and Command:

#Syntax:
locate <keyword>

#Example:
locate OGFile

Password-Less SSH

  • Passwordless SSH in Linux refers to a method of authenticating and establishing SSH (Secure Shell) connections between two machines without the need for entering a password.

  • Instead, it relies on SSH key pairs, consisting of a private key and a corresponding public key.

  • By using passwordless SSH, you can streamline remote access to Linux servers or other machines.

  • It offers several advantages, including increased security (as it eliminates the risk of password-based attacks) and convenience (as you don't need to remember or enter passwords repeatedly).

  • To set up password-less SSH access in Linux, you'll need to generate an SSH key pair on your local machine and then copy the public key to the remote server. Here's a step-by-step guide to help you achieve that:
  1. Generate an SSH key pair:

Open a terminal on your local machine and run the following command:

ssh -keygen
  1. Copy the public key to the remote server:

Use the ssh-copy-id command to copy the public key to the remote server.

ssh -copy -id-i <filename> <username>@[IP]
  1. Now, Restart the service:
systemctl restart ssh
  1. Test the password-less SSH access:

Now, try connecting to the remote server without entering a password:

ssh username@[IP]

If everything was set up correctly, you should be logged in to the remote server without being prompted for a password.

I have covered all the topics that have been covered on Day 3 Workshop. Ok, that's it for the Day 4 blog. I hope you have enjoyed it and please like it.

And Thank You For Reading😊...

21
Subscribe to my newsletter

Read articles from SARTHAK SHINDE directly inside your inbox. Subscribe to the newsletter, and don't miss out.

Written by

SARTHAK SHINDE
SARTHAK SHINDE

Hey guys, I am Sarthak Shinde . Currently studying Diploma in Computer Engineering at Dr. Babasaheb Ambedkar Technological University, Lonere, Raigad.