consolidate ssh utils

This commit is contained in:
AJ ONeal
2020-06-25 02:41:37 +00:00
parent 92fdd2f735
commit bd7e09df58
5 changed files with 42 additions and 0 deletions
+35
View File
@@ -0,0 +1,35 @@
---
title: SSH Utils
homepage: https://webinstall.dev/ssh-utils
tagline: |
SSH Utils: Because --help takes to long.
description: |
SSH Utils includes shortcut commands for some common tasks, including `ssh-pubkey`, `ssh-setpass`, and `ssh-adduser`
---
**ssh-pubkey**:
`ssh-pubkey` will make sure you have an SSH key, and then print it to the screen
and place it in `~/Downloads`.
```bash
ssh-pubkey
```
```txt
~/Downloads/id_rsa.johndoe.pub:
ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQDTOhRnzDJNBNBXVCgkxkEaDM4IAp81MtE8fuqeQuFvq5gYLWoZND39N++bUvjMRCveWzZlQNxcLjXHlZA3mGj1b9aMImrvyoq8FJepe+RLEuptJe3md4EtTXo8VJuMXV0lJCcd9ct+eqJ0jH0ww4FDJXWMaFbiVwJBO0IaYevlwcf0QwH12FCARZUSwXfsIeCZNGxOPamIUCXumpQiAjTLGHFIDyWwLDCNPi8GyB3VmqsTNEvO/H8yY4VI7l9hpztE5W6LmGUfTMZrnsELryP5oRlo8W5oVFFS85Lb8bVfn43deGdlLGkwmcJuXzZfostSTHI5Mj7MWezPZyoSqFLl johndoe@MacBook-Air
```
**ssh-adduser**:
Many modern web programs (`npm` and `postgres`, for example) will not function
correctly if run as root. `ssh-adduser` adds user `me` with the same
**`~/.ssh/authorized_keys`** as the `root` user, with a long random password,
and gives `me` `sudo` privileges.
**ssh-setpass**:
`ssh-setpass` will ask you for your old passphrase (if any) and then for the new
one to reset it with.
+7
View File
@@ -0,0 +1,7 @@
{
rm -f "$HOME/.local/bin/ssh-pubkey" "$HOME/.local/bin/ssh-setpass" "$HOME/.local/bin/ssh-adduser"
webi_download "$WEBI_HOST/packages/ssh-utils/ssh-pubkey.sh" "$HOME/.local/bin/ssh-pubkey"
webi_download "$WEBI_HOST/packages/ssh-utils/ssh-setpass.sh" "$HOME/.local/bin/ssh-setpass"
webi_download "$WEBI_HOST/packages/ssh-utils/ssh-adduser.sh" "$HOME/.local/bin/ssh-adduser"
chmod a+x "$HOME/.local/bin/ssh-"*
}
+37
View File
@@ -0,0 +1,37 @@
#!/bin/bash
set -e
set -u
# TODO: a more complete VPS setup
# TODO would $EUID be better?
if [ "root" != "$(whoami)" ]; then
echo "webi adduser: running user is already a non-root user"
exit 0
fi
#apt-get -y update
#apt-get -y install curl wget rsync git
# Add User
# TODO: might there be a better name?
# me, this, user, self, person, i, who, do, tron
adduser --disabled-password --gecos "" me
my_password=$(openssl rand -hex 16)
printf "$my_password"'\n'"$my_password" | passwd me
adduser me sudo
echo "me ALL=(ALL:ALL) NOPASSWD: ALL" | tee /etc/sudoers.d/me
sudo -i -u me bash -c 'ssh-keygen -b 2048 -t rsa -f /home/me/.ssh/id_rsa -q -N ""'
mkdir -p /home/me/.ssh/
cp -r $HOME/.ssh/authorized_keys /home/me/.ssh/
chmod 0600 me:me /home/me/.ssh/authorized_keys
chown -R me:me /home/me/.ssh/
# Install webi for the new user
sudo -i -u me bash -c 'curl -fsSL https://webinstall.dev/webi | bash' \
|| sudo -i -u me bash -c 'wget -q -O - https://webinstall.dev/webi | bash'
# TODO ensure that ssh-password login is off
echo "Created user 'me' with password '$my_password'"
+25
View File
@@ -0,0 +1,25 @@
#!/bin/bash
set -e
set -u
mkdir -p "$HOME/.ssh/"
if [ ! -f "$HOME/.ssh/id_rsa" ]; then
ssh-keygen -b 2048 -t rsa -f "$HOME/.ssh/id_rsa" -q -N ""
echo ""
fi
if [ ! -f "$HOME/.ssh/id_rsa.pub" ]; then
ssh-keygen -y -f "$HOME/.ssh/id_rsa" > "$HOME/.ssh/id_rsa.pub"
echo ""
fi
# TODO use the comment (if any) for the name of the file
echo ""
echo "~/Downloads/id_rsa.$(whoami).pub":
echo ""
rm -f "$HOME/Downloads/id_rsa.$(whoami).pub":
cp -r "$HOME/.ssh/id_rsa.pub" "$HOME/Downloads/id_rsa.$(whoami).pub"
cat "$HOME/Downloads/id_rsa.$(whoami).pub"
echo ""
+6
View File
@@ -0,0 +1,6 @@
#!/bin/bash
set -e
set -u
ssh-keygen -p -f "$HOME/.ssh/id_rsa"