Differences
This shows you the differences between two versions of the page.
Next revision | Previous revision | ||
home_server:home_server_setup:other_services:ssh [2022-06-26 Sun wk25 09:13] – created baumkp | home_server:home_server_setup:other_services:ssh [2023-12-26 Tue wk52 11:38] (current) – baumkp | ||
---|---|---|---|
Line 1: | Line 1: | ||
+ | {{tag> | ||
======SSH Notes====== | ======SSH Notes====== | ||
- | <- home_server: | + | =====SSH Login Message===== |
+ | ====Acronyms and Definitions==== | ||
+ | *MOTD = Message of the Day | ||
+ | |||
+ | ====Login Messages==== | ||
+ | *'' | ||
+ | *'' | ||
+ | *'' | ||
+ | *'' | ||
+ | |||
+ | ====Login Scripts==== | ||
+ | ====Debian==== | ||
+ | *'' | ||
+ | The Debian script is very simple: | ||
+ | <code bash> | ||
+ | #!/bin/sh | ||
+ | uname -snrvm | ||
+ | </ | ||
+ | |||
+ | ====Ubuntu==== | ||
+ | Ubuntu has multiple scripts some that I like and some that I do not like. | ||
+ | This system status information script, ++++/ | ||
+ | < | ||
+ | #!/bin/sh | ||
+ | # pam_motd does not carry the environment | ||
+ | [ -f / | ||
+ | export LANG | ||
+ | cores=$(grep -c ^processor / | ||
+ | [ " | ||
+ | threshold=" | ||
+ | if [ $(echo "`cut -f1 -d ' ' / | ||
+ | echo | ||
+ | echo -n " | ||
+ | /bin/date | ||
+ | echo | ||
+ | / | ||
+ | else | ||
+ | echo | ||
+ | echo " System information disabled due to load higher than $threshold" | ||
+ | fi</ | ||
+ | ++++ | ||
+ | The main information script is written in python3, ++++/ | ||
+ | < | ||
+ | # | ||
+ | import sys, os | ||
+ | |||
+ | try: | ||
+ | if os.path.dirname(os.path.abspath(sys.argv[0])) == os.path.abspath(" | ||
+ | sys.path.insert(0, | ||
+ | else: | ||
+ | from landscape.lib.warning import hide_warnings | ||
+ | hide_warnings() | ||
+ | |||
+ | from twisted.internet import reactor | ||
+ | |||
+ | from landscape.sysinfo.deployment import run | ||
+ | except ImportError: | ||
+ | # For some reasons the libraries are not importable for now. We are | ||
+ | # probably during an upgrade procedure, so let's exit, expecting the | ||
+ | # dependencies to be fixed at next run. | ||
+ | sys.exit(2) | ||
+ | |||
+ | |||
+ | if __name__ == " | ||
+ | run(sys.argv[1: | ||
+ | |||
+ | </ | ||
+ | *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: | ||
+ | *[[How to manage SSH login message|https:// | ||
+ | *[[HowTo: Set a Warning Message (Banner) in SSH|https:// | ||
+ | *[[Protect SSH Logins with SSH & MOTD Banner Messages|https:// | ||
+ | |||
+ | <- home_server: |