From 4a458b9f9d99827e229943611cf6a150cd41f9b7 Mon Sep 17 00:00:00 2001 From: Nicolas Patouillard Date: Sun, 10 Jul 2022 12:11:18 +0200 Subject: [PATCH] Creating SSH repo --- README.md | 33 +++++++++++ add | 161 +++++++++++++++++++++++++++++++++++++++++++++++++++++ ed0821 | 1 + index.html | 24 ++++++++ pub | 1 + 5 files changed, 220 insertions(+) create mode 100644 README.md create mode 100644 add create mode 100644 ed0821 create mode 100644 index.html create mode 120000 pub diff --git a/README.md b/README.md new file mode 100644 index 0000000..7118423 --- /dev/null +++ b/README.md @@ -0,0 +1,33 @@ +Introduction +============ + +This is the default repository for NPSSI Public SSH Keys + +## Adding me on your server + +### Automatically + +~~~ +wget https://tech.npssi.com/ssh/add +chmod +x add +./add +~~~ + +> **Note:** You can choose one of the public keys from this repo by calling the script like this : +> ~~~ +> ./add ed0821 +> ~~~ + +#### or + +### Manually + +~~~ +cd +wget https://tech.npssi.com/ssh/pub +mkdir .ssh +cat pub >> .ssh/authorized_keys +~~~ +--- + +#### Copyleft © NPSSI diff --git a/add b/add new file mode 100644 index 0000000..6eb6631 --- /dev/null +++ b/add @@ -0,0 +1,161 @@ +#!/bin/bash + +# VARIABLES +script_version="1.3" +ssh_keys_dir="$HOME/.ssh" +netBaseDir="https://tech.npssi.com/ssh/pub" + +##################################### + +npssi_checkCommands() +{ + if ! [ -x "$(command -v wget)" ]; then + show "[x] Error: Please install wget" + exit 1 + fi +} + +npssi_checkCommands + +###################################### + +##### ALL FUNCTIONS USED TO RUN THIS SCRIPT ###### + +# Show the date with style +npssi_showDate() +{ + printf "| %-40s |\n" "`date`" + echo "| " +} + +# Show text with style +npssi_show() +{ + printf "|`tput bold` %-40s `tput sgr0` |\n" "$@" +} + +# Show text with error color +npssi_showerror() +{ + printf "|`tput bold``tput setf 4` %-40s `tput sgr0` |\n" "$@" +} + +# Show text with success color +npssi_showsuccess() +{ + printf "|`tput bold``tput setf 2` %-40s `tput sgr0` |\n" "$@" +} + +# Show the banner +npssi_banner() +{ + echo "+-------------------------------------------+" +} + +# Check network by asking script +npssi_checkNet() +{ + status=$(wget -qO- conntest.npatouillard.net) + if [ "$status" = "ok" ] ; then + echo 0 + return 0 + fi + echo 1 + return 1 +} + +# CREATE .SSH DIR IF NOT EXIST +npssi_sshDir() +{ + if [[ ! -e $ssh_keys_dir ]]; then + if mkdir -p $ssh_keys_dir ; then + echo 0 + return 0 + else + echo 1 + return 1 + fi + fi + echo 0 + return 0 +} + +# CHECK IF THE KEY EXIST +npssi_checkPubKey() +{ + wget -qO- $keyURL + if [ $? = 0 ] ; then + echo 0 + return 0 + fi + echo 1 + return 1 +} + +# ADD public key in .authorized_key +npssi_addPubKey() +{ + echo + echo "#Nicolas Patouillard @NPSSI SSH Key $keyVersion" + ssh_key=$(wget -qO- $keyURL) + echo $ssh_key +} >> $ssh_keys_dir/authorized_keys + +################################################################################ +########## MAIN SCRIPT ########## +################################################################################ + +npssi_banner +npssi_show +npssi_show " Adding SSH Key of Nicolas @NPSSI" +npssi_show " v$script_version" +npssi_show + +keyVersion=$1 +keyURL="$netBaseDir$keyVersion" + +# Checking network +res=$(npssi_checkNet) +if [ "$res" = 1 ]; then + npssi_showerror "[+] Err: Can't access npatouillard's server." + npssi_show + npssi_banner + exit 1 +fi + +# Create .ssh DIR +res=$(npssi_sshDir) +if [ "$res" = 1 ]; then + npssi_showerror "[+] Err: Can't create ssh folder" + npssi_showerror " $ssh_keys_dir" + npssi_show + npssi_banner + exit 1 +fi + +# Check if the key exist in server +res=$(npssi_checkPubKey) +if [ "$res" = 1 ]; then + npssi_showerror "[+] Error: Unable do get the public key" + npssi_show + npssi_showerror "Please : Check if the NAME you entered" + npssi_showerror " is a valid NPSSI Key" + npssi_show + npssi_showerror "NOTE : Leave empty if you don't know" + npssi_show + npssi_banner + exit 1 +fi + +# Adding the public key +npssi_addPubKey + +# Key the IP +IP=$(wget -qO- ip.npatouillard.net) + +npssi_showsuccess " SSH Public key added !" +npssi_showsuccess " Access available from :" +npssi_show +npssi_showsuccess "$USER@$IP" +npssi_banner +exit 0 diff --git a/ed0821 b/ed0821 new file mode 100644 index 0000000..477909c --- /dev/null +++ b/ed0821 @@ -0,0 +1 @@ +ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIHEYMYd5fxdR6KrhcEnZZZUwKBTHI2UL9vQxZmzPcok3 npssi \ No newline at end of file diff --git a/index.html b/index.html new file mode 100644 index 0000000..815ebb3 --- /dev/null +++ b/index.html @@ -0,0 +1,24 @@ +NPSSI - Public SSH Key +

Introduction

+

This is the default repository for NPSSI Public SSH Keys

+

Adding me on your server

+

Automatically

+
wget https://tech.npssi.com/ssh/add
+chmod +x add
+./add
+
+
+

Note: You can choose one of the public keys from this repo by calling the script like this :

+
./add ed0821
+
+
+

or

+

Manually

+
cd
+wget https://tech.npssi.com/ssh/pub
+mkdir .ssh
+cat pub >> .ssh/authorized_keys
+
+
+

Copyleft © NPSSI

+ diff --git a/pub b/pub new file mode 120000 index 0000000..9e24425 --- /dev/null +++ b/pub @@ -0,0 +1 @@ +ed0821 \ No newline at end of file