Compare commits
13 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
54f4d69da6 | ||
|
|
5db69276db | ||
|
|
74bfded26f | ||
|
|
37f9f4429d | ||
|
|
94a970d54b | ||
|
|
c09e8cf799 | ||
|
|
a15541c86b | ||
|
|
12d8d57bd2 | ||
|
|
18b544a1a4 | ||
|
|
4914e3f367 | ||
|
|
12ef307bdb | ||
|
|
d13dd08855 | ||
|
|
2e8c30a704 |
24
Readme.md
24
Readme.md
@@ -16,25 +16,39 @@ chown root. users
|
|||||||
chgrp 600 users
|
chgrp 600 users
|
||||||
```
|
```
|
||||||
|
|
||||||
|
Alternate download: `git clone http://gitlab-ap.factory.tools/scripts-collections/aws-user-create.git users`
|
||||||
|
|
||||||
## Folders
|
## Folders
|
||||||
|
|
||||||
Inside the base folder there are
|
Inside the base folder there are
|
||||||
* ssh-keygen for temporary holding the PEM/PUB files
|
* ssh-keygen for temporary holding the PEM/PUB files
|
||||||
* zip file which holds the created user list, password and PEM/PUB files
|
* zip file which holds the created user list, password and PEM/PUB files
|
||||||
|
|
||||||
|
## Options
|
||||||
|
|
||||||
|
### -t (test)
|
||||||
|
|
||||||
|
Run in test mode. This will *NOT* create any groups or users. Nor will it create any ssh key files.
|
||||||
|
`user_password` output file will be written with `.TEST` extension
|
||||||
|
|
||||||
|
### -i (info)
|
||||||
|
|
||||||
|
Do not created anything at all, just print out info strings
|
||||||
|
|
||||||
## User list creation
|
## User list creation
|
||||||
|
|
||||||
In the `/root/users/` folder there needs to be a file called '*user_list.txt*'
|
In the `/root/users/` folder there needs to be a file called '*user_list.txt*'
|
||||||
|
|
||||||
This is a CSV type file with the following layout
|
This is a CSV type file with the following layout
|
||||||
|
|
||||||
ID | Username | Group | Optional Password | Override host name
|
ID | Username | Group | Optional Password | Override host name | Override ssh key type
|
||||||
-|-|-|-|-
|
-|-|-|-|-|-
|
||||||
|
|
||||||
The ID, Username and Group column must be filled.
|
The ID, Username and Group column must be filled.
|
||||||
For sub groups add them with a *,* The first group is the master group
|
For sub groups add them with a *,* The first group is the master group
|
||||||
If the password column is filled, the string from here will be used as the PEM Key password.
|
If the password column is filled, the string from here will be used as the PEM Key password.
|
||||||
If a override hostname is set it will be used instead of `hostname`
|
If a override hostname is set it will be used instead of `hostname`
|
||||||
|
If the ssh key type is set, it will override the default *ed25519* type. This is not recommended. Only *rsa* is allowed. This is for setting up backwards compatible lists.
|
||||||
|
|
||||||
The ID can be any string in any form.
|
The ID can be any string in any form.
|
||||||
It can also be left empty. It is not used at the moment
|
It can also be left empty. It is not used at the moment
|
||||||
@@ -128,7 +142,7 @@ If the user has been created, the creating will be skipped
|
|||||||
|
|
||||||
## Script output
|
## Script output
|
||||||
|
|
||||||
The generated users and the passwords are stored in the '*user_password.txt*' file
|
The generated users and the passwords are stored in the '*user_password.YYYYMMDD-hhmmss.txt*' file
|
||||||
|
|
||||||
For above the output will be
|
For above the output will be
|
||||||
```
|
```
|
||||||
@@ -154,6 +168,10 @@ This file should be copied localy and then removed from the server
|
|||||||
|
|
||||||
**NOTE** Do not remove the public key data in `ssh-keygen-created-pub/` or the script will create new keys for users in the `user_list.txt` file
|
**NOTE** Do not remove the public key data in `ssh-keygen-created-pub/` or the script will create new keys for users in the `user_list.txt` file
|
||||||
|
|
||||||
|
## SSH helper
|
||||||
|
|
||||||
|
change password or extract public key from pem file
|
||||||
|
|
||||||
### PEM key password reset
|
### PEM key password reset
|
||||||
|
|
||||||
The SSH PEM key password can be reset or changed with
|
The SSH PEM key password can be reset or changed with
|
||||||
|
|||||||
103
bin/check_last_login.sh
Executable file
103
bin/check_last_login.sh
Executable file
@@ -0,0 +1,103 @@
|
|||||||
|
#!/usr/bin/env bash
|
||||||
|
|
||||||
|
# Checks for last access of users in sshallow group
|
||||||
|
# if user login >30days, remoe user from sshallow group and write log
|
||||||
|
|
||||||
|
# base folder
|
||||||
|
BASE_FOLDER=$(dirname $(readlink -f $0))"/";
|
||||||
|
# which group holds the ssh allowed login users (outside of admin users)
|
||||||
|
ssh_group='sshallow';
|
||||||
|
ssh_reject_group='sshreject';
|
||||||
|
# date now for compare
|
||||||
|
now=$(date +"%s");
|
||||||
|
# max age for last login or account create without login
|
||||||
|
max_age_login=60;
|
||||||
|
max_age_create=30;
|
||||||
|
# one day in seconds
|
||||||
|
day=86400;
|
||||||
|
# delete account strings
|
||||||
|
delete_accounts="";
|
||||||
|
user_group_tpl="deluser %s %s;adduser %s %s;";
|
||||||
|
# log base folder
|
||||||
|
LOG="${BASE_FOLDER}/../log";
|
||||||
|
|
||||||
|
if [ $(whoami) != "root" ]; then
|
||||||
|
echo "Script must be run as root user";
|
||||||
|
exit;
|
||||||
|
fi;
|
||||||
|
if [ ! -d "${LOG}" ]; then
|
||||||
|
echo "log folder ${LOG} not found";
|
||||||
|
exit;
|
||||||
|
fi;
|
||||||
|
LOG="${LOG}/check_ssh_user."$(date +"%F_%H%m%S")".log";
|
||||||
|
exec &> >(tee -a "${LOG}");
|
||||||
|
echo "[START] =============>";
|
||||||
|
echo "Hostname : "$(hostname);
|
||||||
|
echo "Run date : "$(date +"%F %T");
|
||||||
|
echo "Max age last login: ${max_age_login} days";
|
||||||
|
echo "Max age no login : ${max_age_create} days";
|
||||||
|
for user in $(cat /etc/group|grep "${ssh_group}:" | cut -d ":" -f 4 | sed -e 's/,/ /g'); do
|
||||||
|
# for user in clemens test42; do
|
||||||
|
account_age=0;
|
||||||
|
delete_user=0;
|
||||||
|
out_string="";
|
||||||
|
#echo "* Checking user ${user}";
|
||||||
|
# check user create time, if we have set it in comment
|
||||||
|
user_create_date=$(cat /etc/passwd | grep "${user}:" | cut -d ":" -f 5);
|
||||||
|
# if empty try last password set time
|
||||||
|
if [ -z "${user_create_date}" ]; then
|
||||||
|
# user L 11/09/2020 0 99999 7 -1
|
||||||
|
user_create_date=$(passwd -S ${user} | cut -d " " -f 3);
|
||||||
|
fi;
|
||||||
|
# last try is user home .bash_logout
|
||||||
|
if [ -z "${user_create_date}" ]; then
|
||||||
|
home_dir=$(cat /etc/passwd | grep "${user}:" | cut -d ":" -f 6)"/.bash_logout";
|
||||||
|
user_create_date=$(stat -c %Z "${home_dir}");
|
||||||
|
fi;
|
||||||
|
# Username Port From Latest
|
||||||
|
# user pts/35 10.110.160.230 Wed Nov 2 09:40:35 +0900 2022
|
||||||
|
last_login_string=$(lastlog -u ${user} | sed 1d);
|
||||||
|
search="Never logged in";
|
||||||
|
# if we have "** Never logged in**" the user never logged in
|
||||||
|
if [ ! -z "${last_login_string##*$search*}" ]; then
|
||||||
|
# find \w{3} \w{3} [\s\d]{2} \d{2}:\d{2}:\d{2} \+\d{4} \d{4}
|
||||||
|
# awk '{for(i=4;i<=NF;++i)printf $i FS}'
|
||||||
|
last_login_date=$(echo "${last_login_string}" | awk '{for(i=4;i<=NF;++i)printf $i FS}' | date +"%s" -f -);
|
||||||
|
# date -d "Wed Nov 2 09:40:35 +0900 2022" +%s
|
||||||
|
last_login=$(awk '{printf("%.0f\n",($1-$2)/$3)}' <<<"${now} ${last_login_date} ${day}");
|
||||||
|
if [ ${last_login} -gt ${max_age_login} ]; then
|
||||||
|
out_string="[!] last logged in ${last_login} days ago";
|
||||||
|
delete_user=1;
|
||||||
|
else
|
||||||
|
out_string="OK";
|
||||||
|
fi;
|
||||||
|
elif [ ! -z "${user_create_date}" ]; then
|
||||||
|
user_create_date=$(echo "${user_create_date}" | date +"%s" -f -);
|
||||||
|
# if all empty, we continue with only check if user has last login date
|
||||||
|
# else get days since creation
|
||||||
|
#account_age=$[ ($(date +"%s")-$(date -d "${user_create_date}" +"%s"))/24 ];
|
||||||
|
account_age=$(awk '{printf("%.0f\n",($1-$2)/$3)}' <<<"${now} ${user_create_date} ${day}");
|
||||||
|
if [ ${account_age} -gt ${max_age_create} ]; then
|
||||||
|
out_string="[!] Never logged in, account created ${account_age} days ago";
|
||||||
|
delete_user=1;
|
||||||
|
else
|
||||||
|
out_string="OK";
|
||||||
|
fi;
|
||||||
|
else
|
||||||
|
out_string="[!!!] Never logged in and we have no create date";
|
||||||
|
fi;
|
||||||
|
# build delete output
|
||||||
|
if [ ${delete_user} = 1 ]; then
|
||||||
|
delete_accounts="${delete_accounts}"$(printf "${user_group_tpl}" "${user}" "${ssh_group}" "${user}" "${ssh_reject_group}")$'\n';
|
||||||
|
fi;
|
||||||
|
printf "* Checking user %-20s: %s\n" "${user}" "${out_string}";
|
||||||
|
done;
|
||||||
|
if [ ! -z "${delete_accounts}" ]; then
|
||||||
|
echo "--------------------->"
|
||||||
|
echo "% Run list below to move users to reject ssh group";
|
||||||
|
echo "";
|
||||||
|
echo "${delete_accounts}";
|
||||||
|
fi;
|
||||||
|
echo "[END] ===============>"
|
||||||
|
|
||||||
|
# __END__
|
||||||
@@ -1,18 +1,19 @@
|
|||||||
#!/bin/bash
|
#!/usr/bin/env bash
|
||||||
|
|
||||||
# * input file
|
# * input file
|
||||||
# user_list.txt
|
# user_list.txt
|
||||||
# <ignored id>;<user name>;<group>[;override password][;override hostname]
|
# <ignored id>;<user name>;<group>[,sub group,sub group];[override password];[override hostname];[override ssh key type]
|
||||||
# lines with # are skipped
|
# lines with # are skipped
|
||||||
# already created users are skipped
|
# already created users are skipped
|
||||||
|
# Mandatory: <ignored id>;<user name>;<group>
|
||||||
# * output file
|
# * output file
|
||||||
# <date>;<target connect host name>;<hostname>;<username>;<password>
|
# <date>;<target connect host name>;<hostname>;<username>;<password>
|
||||||
# If already existing PEM key is used then <password> is [ALREADY SET]
|
# If already existing PEM key is used then <password> is [ALREADY SET]
|
||||||
#
|
#
|
||||||
# * PEM KEY
|
# * PEM KEY
|
||||||
# <hostname>%<group>%<user>%<ssh key type>.pem
|
# <hostname>#<group>#<user>#<ssh key type>.pem
|
||||||
# * PUBLIC KEY
|
# * PUBLIC KEY
|
||||||
# <hostname>%<group>%<user>%<ssh key type>.pem.pub
|
# <hostname>#<group>#<user>#<ssh key type>.pem.pub
|
||||||
# stored as zip in
|
# stored as zip in
|
||||||
# zip/
|
# zip/
|
||||||
#
|
#
|
||||||
@@ -21,28 +22,33 @@
|
|||||||
# They pem pub key must follow the set rules above
|
# They pem pub key must follow the set rules above
|
||||||
|
|
||||||
# SET TO 1 to TEST [will no create user/group/folder]
|
# SET TO 1 to TEST [will no create user/group/folder]
|
||||||
TEST=0;
|
TEST=0; # no creation except ssh keys
|
||||||
while getopts ":t" opt; do
|
INFO=0; # no creation of anything, just print info strings
|
||||||
|
while getopts ":ti" opt; do
|
||||||
case "${opt}" in
|
case "${opt}" in
|
||||||
t|test)
|
t|test)
|
||||||
TEST=1;
|
TEST=1;
|
||||||
;;
|
;;
|
||||||
|
i|info)
|
||||||
|
INFO=1;
|
||||||
|
;;
|
||||||
esac;
|
esac;
|
||||||
done;
|
done;
|
||||||
# hostname for output file only
|
# hostname for output file only
|
||||||
host=$(hostname);
|
host=$(hostname);
|
||||||
timesamp=$(date +%Y%m%d-%H%M%S)
|
timestamp=$(date +%Y%m%d-%H%M%S)
|
||||||
# character to set getween info blocks
|
# character to set getween info blocks
|
||||||
separator="#";
|
separator="#";
|
||||||
# base folder for all data
|
# base folder for all data
|
||||||
root_folder=$(pwd)'/';
|
root_folder=$(pwd)'/';
|
||||||
input_file='user_list.txt';
|
input_file='user_list.txt';
|
||||||
output_file="user_password.${timesamp}.txt";
|
output_file="user_password.${timestamp}.txt";
|
||||||
output_zip_folder='zip/';
|
output_zip_folder='zip/';
|
||||||
output_zip="users.${timesamp}.zip"
|
output_zip="users.${timestamp}.zip"
|
||||||
ssh_keygen_folder='ssh-keygen/';
|
ssh_keygen_folder='ssh-keygen/';
|
||||||
ssh_keygen_folder_created_pub='ssh-keygen-created-pub/';
|
ssh_keygen_folder_created_pub='ssh-keygen-created-pub/';
|
||||||
ssh_keytype='ed25519';
|
ssh_keytype='ed25519';
|
||||||
|
ssh_group='sshallow';
|
||||||
# check if ssh key folder exists
|
# check if ssh key folder exists
|
||||||
if [ ! -d "${root_folder}${ssh_keygen_folder}" ]; then
|
if [ ! -d "${root_folder}${ssh_keygen_folder}" ]; then
|
||||||
mkdir "${root_folder}${ssh_keygen_folder}";
|
mkdir "${root_folder}${ssh_keygen_folder}";
|
||||||
@@ -61,6 +67,11 @@ if [ ! command -v zip &> /dev/null ]; then
|
|||||||
echo "Missing zip application, aborting";
|
echo "Missing zip application, aborting";
|
||||||
exit;
|
exit;
|
||||||
fi;
|
fi;
|
||||||
|
# check if sshallow group exists
|
||||||
|
if [ -z $(cat /etc/group|grep "${ssh_group}:") ]; then
|
||||||
|
echo "Missing ssh access group: ${ssh_group}";
|
||||||
|
exit;
|
||||||
|
fi;
|
||||||
# check if user list file exists
|
# check if user list file exists
|
||||||
if [ ! -f "${root_folder}${input_file}" ]; then
|
if [ ! -f "${root_folder}${input_file}" ]; then
|
||||||
echo "Missing ${root_folder}${input_file}";
|
echo "Missing ${root_folder}${input_file}";
|
||||||
@@ -71,7 +82,7 @@ if [ $(stat -c %a .) != "600" ]; then
|
|||||||
echo "!!!! RECOMMENDED TO HAVE BASE FOLDER SET TO '600' AND USER 'root' !!!!"
|
echo "!!!! RECOMMENDED TO HAVE BASE FOLDER SET TO '600' AND USER 'root' !!!!"
|
||||||
fi;
|
fi;
|
||||||
if [ $(whoami) != "root" ]; then
|
if [ $(whoami) != "root" ]; then
|
||||||
if [ ${TEST} -eq 0 ]; then
|
if [ ${TEST} -eq 0 ] && [ ${INFO} -eq 0 ]; then
|
||||||
echo "Script must be run as root user";
|
echo "Script must be run as root user";
|
||||||
exit;
|
exit;
|
||||||
else
|
else
|
||||||
@@ -83,14 +94,15 @@ cat "${root_folder}${input_file}" |
|
|||||||
while read i; do
|
while read i; do
|
||||||
# skip rows start with # (comment)
|
# skip rows start with # (comment)
|
||||||
if [[ "${i}" =~ ^\# ]]; then
|
if [[ "${i}" =~ ^\# ]]; then
|
||||||
echo -e "";
|
continue;
|
||||||
else
|
fi;
|
||||||
# make lower case, remove spaces
|
# make lower case, remove spaces
|
||||||
user=$(echo "${i}" | cut -d ";" -f 2 | tr A-Z a-z | tr -d ' ');
|
user=$(echo "${i}" | cut -d ";" -f 2 | tr A-Z a-z | tr -d ' ');
|
||||||
_group=$(echo "${i}" | cut -d ";" -f 3 | tr A-Z a-z | tr -d ' ');
|
_group=$(echo "${i}" | cut -d ";" -f 3 | tr A-Z a-z | tr -d ' ');
|
||||||
group=$(echo "${_group}" | cut -d "," -f 1);
|
group=$(echo "${_group}" | cut -d "," -f 1);
|
||||||
sub_group="";
|
sub_group="";
|
||||||
sub_group_opt="";
|
# sshallow group is always added
|
||||||
|
sub_group_opt=" -G ${ssh_group}";
|
||||||
# check if "," inside and extract sub groups
|
# check if "," inside and extract sub groups
|
||||||
if [ -z "${_group##*,*}" ]; then
|
if [ -z "${_group##*,*}" ]; then
|
||||||
sub_group=$(echo "${_group}" | cut -d "," -f 2-);
|
sub_group=$(echo "${_group}" | cut -d "," -f 2-);
|
||||||
@@ -105,20 +117,17 @@ while read i; do
|
|||||||
fi;
|
fi;
|
||||||
# do we have a password preset
|
# do we have a password preset
|
||||||
_password=$(echo "${i}" | cut -d ";" -f 4);
|
_password=$(echo "${i}" | cut -d ";" -f 4);
|
||||||
|
_ssh_keytype=$(echo "${i}" | cut -d ";" -f 6 | tr A-Z a-z | tr -d ' ');
|
||||||
|
if [ "${_ssh_keytype}" = "rsa" ]; then
|
||||||
|
ssh_keytype="${_ssh_keytype}";
|
||||||
|
#echo "[!!] BACKWARDS COMPATIBLE RSA TYPE SELECTION [!!]";
|
||||||
|
fi;
|
||||||
# user & group not set
|
# user & group not set
|
||||||
if [ -z "${user}" ] || [ -z "${_group}" ]; then
|
if [ -z "${user}" ] || [ -z "${_group}" ]; then
|
||||||
echo "[!!!!!] Missing user or group entry for ${user}/${_group}";
|
echo "[!!!!!] Missing user or group entry for ${user}/${_group}";
|
||||||
echo "[ABORT RUN]"
|
echo "[*** ABORT RUN ***]"
|
||||||
break;
|
break;
|
||||||
fi;
|
fi;
|
||||||
# add group for each entry in _group
|
|
||||||
for create_group in ${_group//,/ }; do
|
|
||||||
if [ ${TEST} -eq 0 ]; then
|
|
||||||
groupadd -f ${create_group};
|
|
||||||
else
|
|
||||||
echo "$> groupadd -f ${create_group}";
|
|
||||||
fi;
|
|
||||||
done;
|
|
||||||
# SSH file name part without folder
|
# SSH file name part without folder
|
||||||
ssh_keygen_id="${hostname}${separator}${group}${separator}${user}${separator}${ssh_keytype}.pem";
|
ssh_keygen_id="${hostname}${separator}${group}${separator}${user}${separator}${ssh_keytype}.pem";
|
||||||
# the full file including folder name
|
# the full file including folder name
|
||||||
@@ -127,13 +136,37 @@ while read i; do
|
|||||||
ssh_keyfile_pub="${ssh_keyfile}.pub";
|
ssh_keyfile_pub="${ssh_keyfile}.pub";
|
||||||
# check existing pub file
|
# check existing pub file
|
||||||
ssh_keyfile_check_pub="${root_folder}${ssh_keygen_folder_created_pub}${ssh_keygen_id}.pub";
|
ssh_keyfile_check_pub="${root_folder}${ssh_keygen_folder_created_pub}${ssh_keygen_id}.pub";
|
||||||
|
|
||||||
|
if [ ${INFO} -eq 1 ]; then
|
||||||
|
# test if pub file exists or not, test if user exists
|
||||||
|
echo -n "User: '${user}:${group}(${sub_group})', SSH: ${ssh_keygen_id}";
|
||||||
|
if getent passwd ${user} > /dev/null 2>&1; then
|
||||||
|
echo -n ", User exists";
|
||||||
|
fi;
|
||||||
|
if [ -f "${ssh_keyfile_check_pub}" ]; then
|
||||||
|
echo -n ", SSH Pub key OK";
|
||||||
|
fi;
|
||||||
|
# line break
|
||||||
|
echo "";
|
||||||
|
continue;
|
||||||
|
fi;
|
||||||
|
|
||||||
|
# add group for each entry in _group
|
||||||
|
for create_group in ${_group//,/ }; do
|
||||||
|
if [ ${TEST} -eq 0 ]; then
|
||||||
|
groupadd -f ${create_group};
|
||||||
|
else
|
||||||
|
echo "$> groupadd -f ${create_group}";
|
||||||
|
fi;
|
||||||
|
done;
|
||||||
# check if user is not already created
|
# check if user is not already created
|
||||||
if getent passwd ${user} > /dev/null 2>&1; then
|
if getent passwd ${user} > /dev/null 2>&1; then
|
||||||
echo "-- Skip '${user}:${group}(${sub_group})'";
|
echo "-- Skip '${user}:${group}(${sub_group})'";
|
||||||
else
|
else
|
||||||
echo "++ Create '${user}:${group}(${sub_group})'";
|
echo "++ Create '${user}:${group}(${sub_group})'";
|
||||||
if [ ${TEST} -eq 0 ]; then
|
if [ ${TEST} -eq 0 ]; then
|
||||||
useradd -s /bin/bash -g ${group}${sub_group_opt} -m ${user};
|
# comment is user create time
|
||||||
|
useradd -c `date +"%F"` -s /bin/bash -g ${group}${sub_group_opt} -m ${user};
|
||||||
else
|
else
|
||||||
echo "$> useradd -s /bin/bash -g ${group}${sub_group_opt} -m ${user}";
|
echo "$> useradd -s /bin/bash -g ${group}${sub_group_opt} -m ${user}";
|
||||||
fi;
|
fi;
|
||||||
@@ -151,11 +184,15 @@ while read i; do
|
|||||||
fi;
|
fi;
|
||||||
# create SSH key
|
# create SSH key
|
||||||
echo " > Create ssh key-pair '${ssh_keyfile}'";
|
echo " > Create ssh key-pair '${ssh_keyfile}'";
|
||||||
|
if [ ${TEST} -eq 0 ]; then
|
||||||
ssh-keygen \
|
ssh-keygen \
|
||||||
-t ${ssh_keytype} \
|
-t ${ssh_keytype} \
|
||||||
-f "${ssh_keyfile}" \
|
-f "${ssh_keyfile}" \
|
||||||
-C "${hostname}: ${user}@${group}" \
|
-C "${hostname}: ${user}@${group}" \
|
||||||
-a 100 -N "${password}"
|
-a 100 -N "${password}"
|
||||||
|
else
|
||||||
|
echo "$> ssh-keygen -t ${ssh_keytype} -f ${ssh_keyfile} -C ${hostname}: ${user}@${group} -a 100 -N ${password}";
|
||||||
|
fi;
|
||||||
else
|
else
|
||||||
found=$(grep "$(cat ${ssh_keyfile_check_pub})" /home/${user}/.ssh/authorized_keys);
|
found=$(grep "$(cat ${ssh_keyfile_check_pub})" /home/${user}/.ssh/authorized_keys);
|
||||||
if [ ! -z "${found}" ]; then
|
if [ ! -z "${found}" ]; then
|
||||||
@@ -171,7 +208,11 @@ while read i; do
|
|||||||
fi;
|
fi;
|
||||||
if [ ${skip_ssh} -eq 0 ]; then
|
if [ ${skip_ssh} -eq 0 ]; then
|
||||||
# write login info to output file
|
# write login info to output file
|
||||||
|
if [ ${TEST} -eq 0 ]; then
|
||||||
echo $(date +"%F %T")";"${host}";"${_hostname}";"${user}";"${password} >> ${root_folder}${output_file};
|
echo $(date +"%F %T")";"${host}";"${_hostname}";"${user}";"${password} >> ${root_folder}${output_file};
|
||||||
|
else
|
||||||
|
echo $(date +"%F %T")";"${host}";"${_hostname}";"${user}";"${password} >> ${root_folder}${output_file}".TEST";
|
||||||
|
fi;
|
||||||
# create the SSH foler and authorized access file with correct permissions
|
# create the SSH foler and authorized access file with correct permissions
|
||||||
echo " > Create .ssh folder";
|
echo " > Create .ssh folder";
|
||||||
if [ ${TEST} -eq 0 ]; then
|
if [ ${TEST} -eq 0 ]; then
|
||||||
@@ -196,9 +237,12 @@ while read i; do
|
|||||||
echo "$> chmod 600 /home/${user}/.ssh/authorized_keys";
|
echo "$> chmod 600 /home/${user}/.ssh/authorized_keys";
|
||||||
fi;
|
fi;
|
||||||
fi;
|
fi;
|
||||||
fi;
|
|
||||||
done;
|
done;
|
||||||
|
|
||||||
|
# End before anything because this is just info run
|
||||||
|
if [ ${INFO} -eq 1 ]; then
|
||||||
|
exit;
|
||||||
|
fi;
|
||||||
# zip everything and remove data in ssh key folder, delete output file with passwords
|
# zip everything and remove data in ssh key folder, delete output file with passwords
|
||||||
zip -r \
|
zip -r \
|
||||||
"${root_folder}${output_zip_folder}${output_zip}" \
|
"${root_folder}${output_zip_folder}${output_zip}" \
|
||||||
@@ -219,3 +263,5 @@ else
|
|||||||
echo "$> rm ${root_folder}${output_file}";
|
echo "$> rm ${root_folder}${output_file}";
|
||||||
echo "$> rm ${root_folder}${ssh_keygen_folder}*";
|
echo "$> rm ${root_folder}${ssh_keygen_folder}*";
|
||||||
fi;
|
fi;
|
||||||
|
|
||||||
|
# __END__
|
||||||
|
|||||||
2
log/.gitignore
vendored
Normal file
2
log/.gitignore
vendored
Normal file
@@ -0,0 +1,2 @@
|
|||||||
|
*
|
||||||
|
!.gitignore
|
||||||
@@ -1 +1 @@
|
|||||||
#user_id;user_name;group,subgroup;optional override password;optional override hostname
|
#user_id;user_name;group,subgroup;override password;override hostname;override ssh type
|
||||||
|
|||||||
Reference in New Issue
Block a user