Compare commits
9 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
83f84abd46 | ||
|
|
090d6f9cec | ||
|
|
5659cc010f | ||
|
|
0bd40cdd73 | ||
|
|
5bf30a8b2f | ||
|
|
26c007dba6 | ||
|
|
785e3c116d | ||
|
|
adbfeb0074 | ||
|
|
8c7ef32894 |
2
.shellcheckrc
Normal file
2
.shellcheckrc
Normal file
@@ -0,0 +1,2 @@
|
|||||||
|
shell=bash
|
||||||
|
external-sources=true
|
||||||
25
Readme.md
25
Readme.md
@@ -26,6 +26,31 @@ 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
|
||||||
|
|
||||||
|
## Config
|
||||||
|
|
||||||
|
### create_user.sh: create_user.cfg
|
||||||
|
|
||||||
|
A `create_user.cfg` can be created to set a differen HOME_LOCATION and PASSWORD_LENGTH values
|
||||||
|
|
||||||
|
eg:
|
||||||
|
|
||||||
|
```ini
|
||||||
|
HOME_LOCATION="/storage"
|
||||||
|
PASSWORD_LENGTH=14
|
||||||
|
```
|
||||||
|
|
||||||
|
### authorized_key_location_change.sh: authorized_key_location_change.ignore
|
||||||
|
|
||||||
|
For this script a `authorized_key_location_change.ignore` with a list of user names to ignore for the
|
||||||
|
move
|
||||||
|
|
||||||
|
eg:
|
||||||
|
|
||||||
|
```ini
|
||||||
|
foo_user
|
||||||
|
bar_user
|
||||||
|
```
|
||||||
|
|
||||||
## Options
|
## Options
|
||||||
|
|
||||||
### -g (go)
|
### -g (go)
|
||||||
|
|||||||
@@ -87,6 +87,13 @@ if [ ! -d "${HOME_FOLDER}" ]; then
|
|||||||
echo "Home folder location not found: ${HOME_FOLDER}";
|
echo "Home folder location not found: ${HOME_FOLDER}";
|
||||||
error=1;
|
error=1;
|
||||||
fi;
|
fi;
|
||||||
|
# allow 10 to 39 length for password
|
||||||
|
if [ ! -z "${PASSWORD_LENGTH}" ] && ! [[ "${PASSWORD_LENGTH}" =~ ^[13][0-9]$ ]]; then
|
||||||
|
echo "Password length set error, can only be a value between 10 and 39";
|
||||||
|
error=1;
|
||||||
|
elif [ -z ${PASSWORD_LENGTH} ]; then
|
||||||
|
PASSWORD_LENGTH=14;
|
||||||
|
fi;
|
||||||
# home dir error abort
|
# home dir error abort
|
||||||
if [ $error -eq 1 ]; then
|
if [ $error -eq 1 ]; then
|
||||||
exit;
|
exit;
|
||||||
@@ -309,7 +316,11 @@ while read i; do
|
|||||||
# Note we only create a password if we need it
|
# Note we only create a password if we need it
|
||||||
# password + store pwgen 10 1 -1
|
# password + store pwgen 10 1 -1
|
||||||
if [ -z "${_password}" ]; then
|
if [ -z "${_password}" ]; then
|
||||||
password=$(printf "%s" $(pwgen 14 1));
|
password=$(printf "%s" $(pwgen ${PASSWORD_LENGTH} 1));
|
||||||
|
elif [ "${_password}" = "SET_NO_PASSWORD" ]; then
|
||||||
|
# set empty
|
||||||
|
echo "* No password set";
|
||||||
|
password="";
|
||||||
else
|
else
|
||||||
echo "! Override password set";
|
echo "! Override password set";
|
||||||
password=${_password};
|
password=${_password};
|
||||||
@@ -410,14 +421,24 @@ done;
|
|||||||
if [ ${INFO} -eq 1 ]; then
|
if [ ${INFO} -eq 1 ]; then
|
||||||
exit;
|
exit;
|
||||||
fi;
|
fi;
|
||||||
|
# check if there are any files in the SSH_KEYGEN_FOLDER, else skip zip file creation and file move
|
||||||
|
has_pem_files=0;
|
||||||
|
if (shopt -s nullglob dotglob; f=("${SSH_KEYGEN_FOLDER}"*".pem"*); ((${#f[@]}))); then
|
||||||
|
has_pem_files=1;
|
||||||
|
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
|
||||||
if [ ${TEST} -eq 0 ]; then
|
if [ ${TEST} -eq 0 ]; then
|
||||||
|
if [ "${has_pem_files}" -eq 1 ]; then
|
||||||
zip -r \
|
zip -r \
|
||||||
"${ROOT_FOLDER}${output_zip_folder}${output_zip}" \
|
"${ROOT_FOLDER}${output_zip_folder}${output_zip}" \
|
||||||
"${input_file}" \
|
"${input_file}" \
|
||||||
"${output_file}" \
|
"${output_file}" \
|
||||||
"${SSH_KEYGEN_FOLDER}" \
|
"${SSH_KEYGEN_FOLDER}" \
|
||||||
-x\*.gitignore;
|
-x\*.gitignore;
|
||||||
|
echo "Download: ${ROOT_FOLDER}${output_zip_folder}${output_zip}";
|
||||||
|
else
|
||||||
|
echo "Skip ZIP file creation, no pem files";
|
||||||
|
fi;
|
||||||
else
|
else
|
||||||
echo "zip -r \\"
|
echo "zip -r \\"
|
||||||
echo "${ROOT_FOLDER}${output_zip_folder}${output_zip} \\"
|
echo "${ROOT_FOLDER}${output_zip_folder}${output_zip} \\"
|
||||||
@@ -425,15 +446,19 @@ else
|
|||||||
echo "${output_file} \\"
|
echo "${output_file} \\"
|
||||||
echo "${SSH_KEYGEN_FOLDER} \\"
|
echo "${SSH_KEYGEN_FOLDER} \\"
|
||||||
echo "-x\*.gitignore;"
|
echo "-x\*.gitignore;"
|
||||||
fi;
|
|
||||||
echo "Download: ${ROOT_FOLDER}${output_zip_folder}${output_zip}";
|
echo "Download: ${ROOT_FOLDER}${output_zip_folder}${output_zip}";
|
||||||
|
fi;
|
||||||
# cleam up user log file and ssh keys
|
# cleam up user log file and ssh keys
|
||||||
if [ ${TEST} -eq 0 ]; then
|
if [ ${TEST} -eq 0 ]; then
|
||||||
|
if [ "${has_pem_files}" -eq 1 ]; then
|
||||||
# move pub to created folders
|
# move pub to created folders
|
||||||
mv "${ROOT_FOLDER}${SSH_KEYGEN_FOLDER}"*.pub "${ROOT_FOLDER}${SSH_KEYGEN_FOLDER_CREATED_PUB}";
|
mv "${ROOT_FOLDER}${SSH_KEYGEN_FOLDER}"*.pub "${ROOT_FOLDER}${SSH_KEYGEN_FOLDER_CREATED_PUB}";
|
||||||
# delete the rest
|
# delete the rest
|
||||||
rm "${ROOT_FOLDER}${output_file}";
|
rm "${ROOT_FOLDER}${output_file}";
|
||||||
rm "${ROOT_FOLDER}${SSH_KEYGEN_FOLDER}"*;
|
rm "${ROOT_FOLDER}${SSH_KEYGEN_FOLDER}"*;
|
||||||
|
else
|
||||||
|
echo "Skip pub file move and cleanup, no pem files";
|
||||||
|
fi;
|
||||||
else
|
else
|
||||||
echo "$> mv ${ROOT_FOLDER}${SSH_KEYGEN_FOLDER}*.pub ${ROOT_FOLDER}${SSH_KEYGEN_FOLDER_CREATED_PUB};";
|
echo "$> mv ${ROOT_FOLDER}${SSH_KEYGEN_FOLDER}*.pub ${ROOT_FOLDER}${SSH_KEYGEN_FOLDER_CREATED_PUB};";
|
||||||
echo "$> rm ${ROOT_FOLDER}${output_file}";
|
echo "$> rm ${ROOT_FOLDER}${output_file}";
|
||||||
|
|||||||
Reference in New Issue
Block a user