Differences
This shows you the differences between two versions of the page.
| Both sides previous revisionPrevious revisionNext revision | Previous revision | ||
| home_server:home_server_setup:other_services:ssh [2022-06-26 Sun wk25 13:08] – [Login Scripts] baumkp | home_server:home_server_setup:other_services:ssh [2025-01-10 Fri wk02 10:59] (current) – [Some Links:] baumkp | ||
|---|---|---|---|
| Line 1: | Line 1: | ||
| + | {{tag> | ||
| ======SSH Notes====== | ======SSH Notes====== | ||
| Line 13: | Line 13: | ||
| ====Login Scripts==== | ====Login Scripts==== | ||
| + | ====Debian==== | ||
|   *'' |   *'' | ||
| The Debian script is very simple:  | The Debian script is very simple:  | ||
| - | < | + | < | 
| #!/bin/sh | #!/bin/sh | ||
| uname -snrvm | uname -snrvm | ||
| </ | </ | ||
| + | |||
| + | ====Ubuntu==== | ||
| Ubuntu has multiple scripts some that I like and some that I do not like.   | Ubuntu has multiple scripts some that I like and some that I do not like.   | ||
| - | This system status information script  | + | This system status information script, ++++/ | 
| < | < | ||
| #!/bin/sh | #!/bin/sh | ||
| Line 39: | Line 42: | ||
|     echo " System information disabled due to load higher than $threshold" |     echo " System information disabled due to load higher than $threshold" | ||
| fi</ | fi</ | ||
| - | The main information script is written in python3,  | + | ++++ | 
| + | The main information script is written in python3,  | ||
| < | < | ||
| # | # | ||
| Line 65: | Line 69: | ||
| </ | </ | ||
| + |   *If twisted not installed, '' | ||
| + |   *if cpuinfo not installed, '' | ||
| + | ++++ | ||
| + | ====Python Code==== | ||
| + | ++++python3 agnostic code | | ||
| + | < | ||
| + | # | ||
| + | |||
| + | import psutil | ||
| + | import platform | ||
| + | from datetime import datetime | ||
| + | import cpuinfo | ||
| + | import socket | ||
| + | import uuid | ||
| + | import re | ||
| + | |||
| + | def get_size(bytes, | ||
| + |     """ | ||
| + | Scale bytes to its proper format | ||
| + | e.g: | ||
| + |         1253656 => ' | ||
| + |         1253656678 => ' | ||
| + |     """ | ||
| + | factor = 1024 | ||
| + |     for unit in ["", | ||
| + | if bytes < factor: | ||
| + |             return f" | ||
| + | bytes /= factor | ||
| + | |||
| + | def System_information(): | ||
| + |     print(" | ||
| + | uname = platform.uname() | ||
| + |     print(f" | ||
| + |     print(f" | ||
| + |     print(f" | ||
| + |     print(f" | ||
| + |     print(f" | ||
| + |     print(f" | ||
| + |     print(f" | ||
| + |     print(f" | ||
| + |     print(f" | ||
| + | |||
| + | # Boot Time | ||
| + |     print(" | ||
| + | boot_time_timestamp = psutil.boot_time() | ||
| + | bt = datetime.fromtimestamp(boot_time_timestamp) | ||
| + |     print(f" | ||
| + | |||
| + | # print CPU information | ||
| + |     print(" | ||
| + | # number of cores | ||
| + |     print(" | ||
| + |     print(" | ||
| + | # CPU frequencies | ||
| + | cpufreq = psutil.cpu_freq() | ||
| + |     print(f" | ||
| + |     print(f" | ||
| + |     print(f" | ||
| + | # CPU usage | ||
| + |     print(" | ||
| + |     for i, percentage in enumerate(psutil.cpu_percent(percpu=True, | ||
| + |         print(f" | ||
| + |     print(f" | ||
| + | |||
| + | # Memory Information | ||
| + |     print(" | ||
| + | # get the memory details | ||
| + | svmem = psutil.virtual_memory() | ||
| + |     print(f" | ||
| + |     print(f" | ||
| + |     print(f" | ||
| + |     print(f" | ||
| + | |||
| + |     print(" | ||
| + | # get the swap memory details (if exists) | ||
| + | swap = psutil.swap_memory() | ||
| + |     print(f" | ||
| + |     print(f" | ||
| + |     print(f" | ||
| + |     print(f" | ||
| + | |||
| + | # Disk Information | ||
| + |     print(" | ||
| + |     print(" | ||
| + | # get all disk partitions | ||
| + | partitions = psutil.disk_partitions() | ||
| + | for partition in partitions: | ||
| + |         print(f" | ||
| + |         print(f"  | ||
| + |         print(f"  | ||
| + | try: | ||
| + | partition_usage = psutil.disk_usage(partition.mountpoint) | ||
| + |         except PermissionError: | ||
| + | # this can be catched due to the disk that | ||
| + | # isn't ready | ||
| + | continue | ||
| + |         print(f"  | ||
| + |         print(f"  | ||
| + |         print(f"  | ||
| + |         print(f"  | ||
| + | # get IO statistics since boot | ||
| + | disk_io = psutil.disk_io_counters() | ||
| + |     print(f" | ||
| + |     print(f" | ||
| + | |||
| + | ## Network information | ||
| + |     print(" | ||
| + | ## get all network interfaces (virtual and physical) | ||
| + | if_addrs = psutil.net_if_addrs() | ||
| + |     for interface_name, | ||
| + |         for address in interface_addresses: | ||
| + |             print(f" | ||
| + |             if str(address.family) == ' | ||
| + |                 print(f"  | ||
| + |                 print(f"  | ||
| + |                 print(f"  | ||
| + |             elif str(address.family) == ' | ||
| + |                 print(f"  | ||
| + |                 print(f"  | ||
| + |                 print(f"  | ||
| + | ##get IO statistics since boot | ||
| + | net_io = psutil.net_io_counters() | ||
| + |     print(f" | ||
| + |     print(f" | ||
| + | |||
| + | if __name__ == " | ||
| + | |||
| + | System_information() | ||
| + | </ | ||
| + | ++++ | ||
| - | Some Links: | + | ====Some Links:==== | 
| - |   *[[How to manage SSH login message|https:// | + |   *[[https:// | 
| - |   *[[HowTo: Set a Warning Message (Banner) in SSH|https:// | + |   *[[https:// | 
| - |   *[[Protect SSH Logins with SSH & MOTD Banner Messages|https:// | + |   *[[https:// | 
| <- home_server: | <- home_server: | ||