39 lines
1.3 KiB
Bash
Executable File
39 lines
1.3 KiB
Bash
Executable File
#!/bin/bash --posix
|
|
|
|
set -e
|
|
|
|
# Remote System
|
|
REMOTE_SSH_SERVER=Kansas-3800X
|
|
REMOTE_HOST_NAME=69.30.230.226
|
|
REMOTE_USER_TO_CREATE=Mordhau
|
|
|
|
# Local System
|
|
SSH_FILE_DIRECTORY=~/.ssh
|
|
SSH_FILE_NAME=${REMOTE_USER_TO_CREATE}-id_edcsa
|
|
SSH_FILE=${SSH_FILE_DIRECTORY}/${SSH_FILE_NAME}
|
|
SSH_HOST=Kansas-3800X
|
|
|
|
ssh-keygen -b 521 -t ECDSA -f ${SSH_FILE} -N ""
|
|
chmod 600 ${SSH_FILE}
|
|
|
|
PUB_KEY_CONTENTS=$(cat ${SSH_FILE}.pub)
|
|
|
|
ssh ${REMOTE_SSH_SERVER} -f "useradd ${REMOTE_USER_TO_CREATE}; bash -l"
|
|
ssh ${REMOTE_SSH_SERVER} -f "mkdir /home/${REMOTE_USER_TO_CREATE}/.ssh; bash -l"
|
|
ssh ${REMOTE_SSH_SERVER} -f "touch /home/${REMOTE_USER_TO_CREATE}/.ssh/authorized_keys; bash -l"
|
|
ssh ${REMOTE_SSH_SERVER} -f "echo ${PUB_KEY_CONTENTS} >> /home/${REMOTE_USER_TO_CREATE}/.ssh/authorized_keys; bash -l"
|
|
ssh ${REMOTE_SSH_SERVER} -f "chown -R ${REMOTE_USER_TO_CREATE}:${REMOTE_USER_TO_CREATE} /home/${REMOTE_USER_TO_CREATE}/.ssh; bash -l"
|
|
|
|
cat << EOF >> ~/.ssh/config
|
|
Host ${SSH_HOST}
|
|
HostName ${REMOTE_HOST_NAME}
|
|
Match user ${REMOTE_USER_TO_CREATE}
|
|
Identityfile ${SSH_FILE}
|
|
LogLevel INFO
|
|
EOF
|
|
|
|
ssh ${REMOTE_USER_TO_CREATE}@${SSH_HOST} -f "mkdir ~/.bin"
|
|
ssh ${REMOTE_USER_TO_CREATE}@${SSH_HOST} -f "echo export PATH=$PATH:~/.bin > ~/.bash_profile"
|
|
|
|
echo
|
|
echo "Finished, login via ssh with \"${REMOTE_USER_TO_CREATE}@${SSH_HOST}\"" |