How to Log in Using SSH and Essential Linux Commands for Daily Management Print

  • 0

Introduction

Secure Shell (SSH) is a protocol used to securely connect to remote servers. It's a critical tool for system administrators, developers, and anyone needing to manage a Linux server. In this article, we'll cover how to log in using SSH and the essential commands needed for daily management of a Linux system.

Logging in Using SSH

Prerequisites

  • A Linux server with SSH enabled.
  • SSH client installed on your local machine (most Unix-like systems have this by default; Windows users can use tools like PuTTY or OpenSSH).

Steps to Log in Using SSH

  1. Open Your Terminal or SSH Client:

    • On Unix-like systems (Linux, macOS), open the terminal.
    • On Windows, you can use PowerShell or an SSH client like PuTTY.
  2. Use the SSH Command: The basic syntax to connect to a server via SSH is:

ssh username@hostname_or_ip
Replace `username` with your actual username on the server and `hostname_or_ip` with the server's domain name or IP address.

 

3. Specify a Port Number (if different from the default port 22):
ssh -p port_number username@hostname_or_ip

 

4. Specify a Different Login Name:
ssh -l username hostname_or_ip

 

5. Accept the Host Key:
On your first connection, you’ll see a message like this:
The authenticity of host 'hostname (ip)' can't be established.
RSA key fingerprint is xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx.
Are you sure you want to continue connecting (yes/no)?
Type `yes` and press Enter.

 

6. Enter Your Password:
When prompted, enter your password. Note that the terminal won’t show any characters as you type. Press Enter after typing your password.

 

7. Successful Login:
After successful authentication, you’ll have access to the server’s shell.

 

Removing Old Host Keys

 

If you encounter an error due to changed host keys (e.g., after a server reinstallation or IP address change), use the following command to remove the old host key:
 
ssh-keygen -R hostname_or_ip

 

Essential Commands for Daily Management

 

File and Directory Operations

 

1. Listing Files and Directories:
ls
Options:
-`ls -l` : Long listing format
-`ls -a` : Include hidden files
-`ls -lh` : Human-readable format

 

2. Changing Directory:
cd /path/to/directory

 

3. Creating Directories:
mkdir new_directory

 

4. Removing Files and Directories:
rm filename
rm -r directory

 

5. Copying Files:
cp source destination

 

6. Moving/Renaming Files:
mv source destination

 

7. Viewing File Contents:
cat filename
less filename

 

User and Permission Management

 

1. Checking User Information:
whoami
id

 

2. Adding a New User:
sudo adduser new_username

 

3. Changing User Password:
passwd username

 

4. Changing File Permissions:
chmod permissions filename
Example:
-`chmod 755 script.sh` : Read, write, execute for owner; read and execute for group and others.

 

5. Changing File Ownership:
chown owner:group filename

 

Process Management

 

1. Viewing Running Processes:
ps aux
top

 

2. Killing a Process:
kill process_id
kill -9 process_id

 

3. Checking System Resource Usage:
free -h
df -h

 

Network Management

 

1. Checking Network Configuration:
ifconfig
ip addr

 

2. Checking Network Connectivity:
ping hostname_or_ip

 

3. Using SSH for Port Forwarding:
ssh -L local_port:remote_host:remote_port username@hostname

 

Package Management (Debian/Ubuntu)

 

1. Updating Package Lists:
sudo apt update

 

2. Upgrading Installed Packages:
sudo apt upgrade

 

3. Installing a New Package:
sudo apt install package_name

 

4. Removing a Package:
sudo apt remove package_name

 

Package Management (RHEL/CentOS)

 

1. Updating Package Lists:
sudo yum check-update

 

2. Upgrading Installed Packages:
sudo yum update

 

3. Installing a New Package:
sudo yum install package_name

 

4. Removing a Package:
sudo yum remove package_name

 

Logs and Monitoring

 

1. Viewing System Logs:
tail -f /var/log/syslog

 

2. Checking Disk Usage:
du -sh /path/to/directory

 

3. Monitoring System Performance:
vmstat
iostat

 

Conclusion

Mastering SSH and essential Linux commands is crucial for effective server management. This guide provides a foundation for logging in and performing basic administrative tasks. As you become more familiar with these commands, you’ll be able to handle more complex scenarios and streamline your workflow.

For more advanced usage and troubleshooting, refer to our comprehensive knowledge base at www.domainindia.com/knowledgebase or submit a ticket for further assistance at www.domainindia.com/support.


Was this answer helpful?

« Back