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 is a critical tool for system administrators, developers, and anyone managing Linux systems. SSH provides secure access, enabling users to execute commands, transfer files, and perform administrative tasks remotely. This guide will walk you through logging in using SSH and essential Linux commands for effective server management.


Logging in Using SSH

Prerequisites

  1. A Linux server with SSH enabled.
  2. An SSH client installed on your local machine:
    • Linux/macOS: SSH is pre-installed in the terminal.
    • Windows: Use PowerShell (OpenSSH) or a third-party client like PuTTY.
Download PuTTY - a free SSH and telnet client for Windows

 


Steps to Log in Using SSH

  1. Open Your Terminal or SSH Client:

    • On Linux or macOS, open the terminal application.
    • On Windows, use PowerShell (OpenSSH) or PuTTY.
  2. Run the SSH Command:
    ssh username@hostname_or_ip
    Replace username with your server’s username 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 the first connection, you’ll see a message like:
    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

     

    .
    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 will not 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 or 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 a user password:
    passwd username

  4. Changing file permissions:
    chmod permissions filename
    Example:
    chmod 755 script.sh

  5. Changing file ownership:
    chown owner

     

    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

     

    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