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
- A Linux server with SSH enabled.
- 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.
Steps to Log in Using SSH
-
Open Your Terminal or SSH Client:
- On Linux or macOS, open the terminal application.
- On Windows, use PowerShell (OpenSSH) or PuTTY.
-
Run the SSH Command:
ssh username@hostname_or_ip
Replaceusername
with your server’s username andhostname_or_ip
with the server’s domain name or IP address. -
Specify a Port Number (if different from the default port 22):
ssh -p port_number username@hostname_or_ip -
Specify a Different Login Name:
ssh -l username hostname_or_ip -
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)?
Typeyes
and press Enter. -
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. -
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
-
Listing files and directories:
ls
Options:- ls -l : Long listing format
- ls -a : Include hidden files
- ls -lh : Human-readable format
-
Changing directory:
cd /path/to/directory -
Creating directories:
mkdir new_directory -
Removing files and directories:
rm filename
rm -r directory -
Copying files:
cp source destination -
Moving or renaming files:
mv source destination -
Viewing file contents:
cat filename
less filename
User and Permission Management
-
Checking user information:
whoami
id -
Adding a new user:
sudo adduser new_username -
Changing a user password:
passwd username -
Changing file permissions:
chmod permissions filename
Example:
chmod 755 script.sh -
Changing file ownership:
chown ownerfilename
Process Management
-
Viewing running processes:
ps aux
top -
Killing a process:
kill process_id
kill -9 process_id -
Checking system resource usage:
free -h
df -h
Network Management
-
Checking network configuration:
ifconfig
ip addr -
Checking network connectivity:
ping hostname_or_ip -
Using SSH for port forwarding:
ssh -L local_port:remote_hostusername@hostname
Package Management (Debian/Ubuntu)
-
Updating package lists:
sudo apt update -
Upgrading installed packages:
sudo apt upgrade -
Installing a new package:
sudo apt install package_name -
Removing a package:
sudo apt remove package_name
Package Management (RHEL/CentOS)
-
Updating package lists:
sudo yum check-update -
Upgrading installed packages:
sudo yum update -
Installing a new package:
sudo yum install package_name -
Removing a package:
sudo yum remove package_name
Logs and Monitoring
-
Viewing system logs:
tail -f /var/log/syslog -
Checking disk usage:
du -sh /path/to/directory -
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.