SSH , Find and Locate in linux!!!

Heloo Everyone!! Sejal Marawade here let's start with new blog Day-4 linux Workshop led by Pranav Jambare Sir

In todays session the following topics were cleared !

•SSH :

•SSH, also known as Secure Shell or Secure Socket Shell.

•It is a network protocol that gives users, particularly system administrators, a secure way to access a computer over an unsecured network.

•SSH is widely used by network administrators to manage systems and applications remotely, enabling them to log in to another computer over a network, execute commands and move files from one computer to another.

•It uses port 22 for data transfer.

There are two keys that are responsible for secure authentication and communication between two systems. These are public and private keys.

•Public key: It is meant to be shared with other computers or servers that you want to connect to. Simply this means that this is not secret and can be freely distributed.

•Private key: It is a secret key that remains on our local computer. It cannot be distributed for the need of security. It is used for authentication.

•Syntax:

ssh [username]@[IPaddress]

•Creating an SSH Connection:

To run the SSH command these two packages must be installed:

openssh -server

openssh -client

•The Syntax for Installing Packages:

$ yum install [packagename]
# $ yum install openssh-server
# $ yum install openssh-client

•The syntax for checking port 22:

netstat -tunlp|grep 22

•The syntax for checking the status of service:

systemctl status [serviceName]

#Example : systemctl status sshd

•syntax for restarting the service:

systemctl restart [service_name]

•syntax for stopping the service:

systemctl stop [service_name]

•syntax for starting the service:

systemctl start [service_name]

•syntax for connecting servers remotely:

$ ssh username@hostid
# ssh root@132.167.122.1

•Connecting different servers by allowing or denying users:

vim /etc/ssh/sshd_config

#Syntax
AllowUsers <username>
DenyUsers <username>
#Command
AllowUsers sejall
DenyUsers vedika

Allow or Deny the user to connect with the server : For doing such a thing you have to navigate to /etc/ssh/sshd_config file :

vim /etc/host.allow # To allow the network
vim /etc/host.deny #To deny the network

•Find command :

•Find is a command used to search for a file and directory.

•The find command searches the files based on the size, permission, type, group, time, and date.

•The find command is a more aggressive search tool than locate. Find is able to recursively search any given path for various files.

•It scans the file system dynamically.

•It produces real-time outputs.

find [from where to search / source] [what to find] [-options] [file_name or directory_name]
#Example :
find /-name [file_name]

•There are options of "find" that are mentioned below-

-name : Searches for files with a specific name or pattern.

-type : Filters files based on their type (regular files, directories, symbolic links)

-size: Searches for files based on their size.

-user: Searches for files owned by a specific user.

-group: Finds files belonging to a specific group.

-perm: Searches for files with specific permissions .(e.g., -perm 644 for files with read/write permissions for the owner and read-only for others).

-exec: Executes a command on the found files (e.g., -exec rm {}; to delete the found files).

-empty: Finds empty files or directories.

•Locate Command:

•locate command in Linux is used to find the files by name.

•It regularly updates the database for efficient searching.

•The locate utility works better and faster than find command counterpart because instead of searching the file system when a file search is initiated, it would look through a database.

•The locate command doesn't search the entire file system , but looks through a regularly updated file database in the system .

•It searches through a prebuilt local database of all files on the filesystem generated by the updatedb command.

•For updating the database :

#Syntax
updatedb
General Syntax :

#Syntax
locate <filename>
#Example
locate Samplefile

•Passwordless SSH :

The passwordless SSH protocol uses a process where your device establishes a connection with a remote computer without the need of you keying in a password. The improved alternative eliminates the need to use complex passwords that are hard to recall. Thus, the passwordless SSH protocol protects its users from common password-based attacks.

Step 1: Generate a key pair :

Use ssh-keygen to generate a key pair consisting of a public key and a private key on the client computer. This command can be run on any modern Linux client distribution, the Terminal in macOS.

#Syntax

ssh -keygen

The private key will be saved in the default location – .ssh/id_rsa file.

The public key will be saved in the default location – .ssh/id_rsa.pub file.

Then, copy the public key to enable password-less ssh :

#Syntax

ssh-copy -id -i -id -<filename> <username>@<IP_Address>

•To restart the service and check if the connection established is password-less or not :

#Syntax

systemctl restart <service name> #To restart the service

ssh <username>@<IP_Address> #To established the connection.

Thankyouu for reading my blog !!!!

10
Subscribe to my newsletter

Read articles from CO 50 MARAWADE SEJAL directly inside your inbox. Subscribe to the newsletter, and don't miss out.

Written by

CO 50 MARAWADE SEJAL
CO 50 MARAWADE SEJAL