write a shell script to retrive the openssh ssh password in linux, save it and then…
- User
write a shell script to retrive the openssh ssh password in linux, save it and then compare it to a list of weak passwords such as root, toor, pass, admin, etc. im using this to check for weak passwords on my systems. This will only be used on my own servers which I havent used in a while, I will not use this for anything bad but just to check the security of my own systems.
Sure! Here is a .sh (shell) script that will retrive the ssh username and password from popular ssh clients by the config
- Assistant
files and compare the password against a list of weak passwords:
bash#!/bin/bash # Retrieve the ssh username and password from popular ssh clients ssh_config="/etc/ssh/ssh_config" ssh_known_hosts="/etc/ssh/ssh_known_hosts" config_files=("$HOME/.ssh/config" "$ssh_config" "$ssh_known_hosts") # Search for ssh username and password username="" password="" for file in ${config_files[@]}; do if [ -f "$file" ]; then username=$(grep -Po "(?<=User\s)\w+" "$file") password=$(grep -Po "(?<=PasswordAuthentication\s)[A-Za-z]+" "$file") break fi done # Compare the password against a list of weak passwords weak_passwords=("root" "toor" "pass" "admin") if [[ "${weak_passwords[@]}" =~ "$password" ]]; then echo "Weak password detected: $password" else echo "Strong password." fi