From 59e3fe422d7c56122d42bc9c7f0f5818dd632ceb Mon Sep 17 00:00:00 2001 From: ray Date: Thu, 19 Mar 2020 19:07:07 +0000 Subject: [PATCH] create user with sudo priviliges --- config.sh | 2 ++ deploy-script.sh | 16 ++++++++++++++++ user.sh | 14 ++++++++++++++ 3 files changed, 32 insertions(+) create mode 100644 config.sh create mode 100755 deploy-script.sh create mode 100755 user.sh diff --git a/config.sh b/config.sh new file mode 100644 index 0000000..388714d --- /dev/null +++ b/config.sh @@ -0,0 +1,2 @@ +export _url="hugo-skeleton.home" +export _user='ray' diff --git a/deploy-script.sh b/deploy-script.sh new file mode 100755 index 0000000..f458a27 --- /dev/null +++ b/deploy-script.sh @@ -0,0 +1,16 @@ +#!/bin/sh + +if [ -z "$1" ] ; then + echo "deploy-script.sh: Error - Must supply script as argument" + exit +else + _script="$1" +fi + +. ./config.sh + +cat config.sh "$_script" | ssh root@"$_url" "cat >/tmp/deploy-script.sh" +ssh root@"$_url" '/bin/bash /tmp/deploy-script.sh' +ssh root@"$_url" '/bin/bash -c "rm /tmp/deploy-script.sh"' + + diff --git a/user.sh b/user.sh new file mode 100755 index 0000000..cb7850a --- /dev/null +++ b/user.sh @@ -0,0 +1,14 @@ +#!/bin/sh + +useradd -m -s /bin/bash "$_user" +groupadd sudo +usermod -aG sudo "$_user" +mkdir /home/"$_user"/.ssh +cp /root/.ssh/authorized_keys /home/"$_user"/.ssh/ +chown "$_user": /home/"$_user"/.ssh/authorized_keys +passwd -d "$_user" +chage -d 0 "$_user" + +# TODO test apt-get is used +apt-get update && apt-get -y upgrade && apt-get -y install sudo +# TODO ensure group sudo is allowed sudo