diff --git a/bin/create_user.sh b/bin/create_user.sh index 78ef382..c12b940 100755 --- a/bin/create_user.sh +++ b/bin/create_user.sh @@ -247,9 +247,9 @@ while read i; do echo "++ Create '${username}:${group}(${sub_group})'"; if [ ${TEST} -eq 0 ]; then # comment is user create time - useradd -c `date +"%F"` -s /bin/bash -g ${group}${sub_group_opt} -d "${HOME_FOLDER}" -m ${username}; + useradd -c `date +"%F"` -s /bin/bash -g ${group}${sub_group_opt} -d "${HOME_FOLDER}${username}" -m ${username}; else - echo "$> useradd -c `date +"%F"` -s /bin/bash -g ${group}${sub_group_opt} -d "${HOME_FOLDER}" -m ${username}"; + echo "$> useradd -c `date +"%F"` -s /bin/bash -g ${group}${sub_group_opt} -d "${HOME_FOLDER}${username}" -m ${username}"; fi; fi; # set the auth file @@ -281,7 +281,10 @@ while read i; do echo "$> ssh-keygen -t ${ssh_keytype} -f ${ssh_keyfile} -C ${hostname}: ${username}@${group} -a 100 -N ${password}"; fi; else - found=$(grep "$(cat ${ssh_keyfile_check_pub})" ${SSH_AUTHORIZED_FILE}); + found=''; + if [ -f "${SSH_AUTHORIZED_FILE}" ]; then + found=$(grep "$(cat ${ssh_keyfile_check_pub})" ${SSH_AUTHORIZED_FILE}); + fi; if [ ! -z "${found}" ]; then skip_ssh=1; echo "-- Skip SSH Key creation: ${ssh_keygen_id}.pub"; @@ -303,7 +306,7 @@ while read i; do echo $(date +"%F %T")";"${host}";"${_hostname}";"${username}";"${password}";"${ssh_allow_type} >> ${create_output_file}; # create folder only if we do not have central # create the SSH foler and authorized access file with correct permissions - if [ ! -z "${SSH_CENTRAL_AUTHORIZED_FILE_FOLDER}" ]; then + if [ -z "${SSH_CENTRAL_AUTHORIZED_FILE_FOLDER}" ]; then echo " > Create .ssh folder"; if [ ${TEST} -eq 0 ]; then mkdir ${HOME_FOLDER}${username}/.ssh/; @@ -314,12 +317,18 @@ while read i; do # add echo " > Add public into authorized_keys file"; if [ ${TEST} -eq 0 ]; then - if [ ! -z "${SSH_CENTRAL_AUTHORIZED_FILE_FOLDER}" ]; then + if + [ ! -z "${SSH_CENTRAL_AUTHORIZED_FILE_FOLDER}" ] && + [ -f "${SSH_AUTHORIZED_FILE}" ]; + then chattr -i ${SSH_AUTHORIZED_FILE}; fi; cat "${ssh_keyfile_pub}" > ${SSH_AUTHORIZED_FILE}; else - if [ ! -z "${SSH_CENTRAL_AUTHORIZED_FILE_FOLDER}" ]; then + if + [ ! -z "${SSH_CENTRAL_AUTHORIZED_FILE_FOLDER}" ] && + [ -f "${SSH_AUTHORIZED_FILE}" ]; + then echo "$> chattr -i ${SSH_AUTHORIZED_FILE}"; fi; echo "$> cat ${ssh_keyfile_pub} > ${SSH_AUTHORIZED_FILE}";