Skip to content

This guide walks through setting up SSH between two machines on the same network, logging into another system, and managing logs.

Notifications You must be signed in to change notification settings

panwar100/linux-ssh-logging-guide

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 
 
 

Repository files navigation

linux-ssh-logging-guide

This guide walks through setting up SSH between two machines on the same network, logging into another system, and managing logs.

Index

1. Simple SSH

2. SSH Key-Based Authentication

3. Allow/Deny Users for SSH

4. Log Management


Steps for SSH Setup Between Two Machines

1.Simple SSH

  • Checking Network Connectivity

Ensure both machines are on the same network and get their IP addresses:

On Machine A:

ifconfig Or ip a

Screenshot from 2024-12-01 21-52-49

On Machine B:

Screenshot from 2024-12-01 21-54-37

  • Testing Ping

Check connectivity between machines:

Screenshot from 2024-12-01 21-56-07

  • Login to Machine B

a) Verify the user is available:

Screenshot from 2024-12-01 21-58-08

Screenshot from 2024-12-01 21-58-23

b) Log in as the user ritik from Machine A:

Screenshot from 2024-12-01 23-59-09

c) On Machine B, verify the directory and file:

Create a file as user ritik through Machine A:

Screenshot from 2024-12-01 22-04-08

Verify on Machine B:

Screenshot from 2024-12-01 22-05-55


  • Login as Root

Log in as the root user on Machine B:

Screenshot from 2024-12-01 22-25-09

2.SSH Key-Based Authentication

  • Generate SSH Key on Machine A:

Screenshot from 2024-12-01 22-30-56

Files: id_rsa (private key) and id_rsa.pub (public key)

  • Copy Public Key to Machine B:

Screenshot from 2024-12-01 22-33-25

Enter the password when prompted.

  • Verify Password-less Login:

Screenshot from 2024-12-01 22-34-54

3.Allow/Deny Users for SSH

  • Edit SSH configuration on Machine B:

vim /etc/ssh/sshd_config

  • Add the following lines under Authentication:

AllowUsers ritik root

DenyUsers harry

Screenshot from 2024-12-01 22-40-07

  • Restart the SSH service:

Screenshot from 2024-12-01 22-41-59

  • Test logging in with different users:

Screenshot from 2024-12-01 22-49-34

ssh [email protected] # Should fail

Screenshot from 2024-12-01 22-48-59

ssh [email protected] # Should succeed

4.Log Management

Access System Logs

  • A. View logs:

Screenshot from 2024-12-01 23-16-22

Explain:

System Logs:

  • boot.log: Contains logs related to the system boot process.

  • messages: General system messages that may contain errors, warnings, or general system activity.

  • secure: Contains authentication and authorization logs, such as SSH login attempts, sudo, and other security-related events.

  • cron: Logs related to cron jobs, which are scheduled tasks on the system.

  • lastlog: Contains information about the last login times for all users.

  • wtmp: A binary file that logs all logins and logouts on the system.

  • btmp: Logs failed login attempts.

  • audit: Contains audit logs, which track various security-relevant events on the system.

VMware Logs:

  • vmware-network.log, vmware-vmsvc-root.log, etc.: Logs related to VMware virtual machines and services. These files might be used for diagnosing issues with VMware tools or networking.

Application-Specific Logs:

  • dmesg: Kernel logs related to system hardware and driver issues.

  • firewalld: Logs related to the firewall service.

  • sssd: Logs for the System Security Services Daemon, which provides authentication services.

  • rhsm: Red Hat Subscription Manager logs.

  • insights-client: Logs from the Red Hat Insights client, which provides system diagnostics.

Other Logs:

  • tuned: Logs related to the tuning of system settings for performance.

  • cups: Logs from the Common Unix Printing System, related to printer management.

  • xferlog: Logs related to FTP transfers.

  • samba: Logs related to the Samba file-sharing service.

Older Log Files:

  • messages-20241124, secure-20241124: These are archived log files, probably for previous dates. They can be helpful for reviewing past events.

  • B. Use journalctl for logs:

    journalctl is a command-line utility used to query and display log entries from the systemd journal. This tool is part of the systemd suite and is used to view logs recorded by system services, the kernel, and other system components in a centralized manner.

Screenshot from 2024-12-01 23-28-17

a) View the last 5 logs:

Screenshot from 2024-12-01 23-28-56

b) View detailed logs:

journalctl -xe

shows the most recent log entries and adds extra details, making it easier to troubleshoot errors, warnings, or system issues.

Screenshot from 2024-12-01 23-30-36

c) View logs with specific priority:

-Error logs

journalctl -p err or journalctl -p 3

Screenshot from 2024-12-01 23-34-16

Check more:

Screenshot from 2024-12-01 23-36-51


C. Filter logs by PID or service:

  • by PID

Screenshot from 2024-12-01 23-38-44

  • by service

Screenshot from 2024-12-01 23-39-49

5.Custom Log Configuration

  • Create a custom log file:

Screenshot from 2024-12-01 23-48-36

  • Configure rsyslog:

Screenshot from 2024-12-01 23-51-26

Add:

*.debug /var/log/MY_log

Screenshot from 2024-12-01 23-50-29

  • Restart the rsyslog service:

systemctl restart rsyslog.service

  • Test by adding logs:

Screenshot from 2024-12-01 23-54-52

The logger command in Linux is used to write custom messages to the system log (typically managed by rsyslog or journalctl). The command interacts with the syslog system, allowing users or scripts to log messages for troubleshooting, auditing, or informational purposes.

Screenshot from 2024-12-01 23-55-55

About

This guide walks through setting up SSH between two machines on the same network, logging into another system, and managing logs.

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published