sshjump/host/setup.sh

24 lines
776 B
Bash
Raw Normal View History

2018-06-05 15:32:51 -04:00
#!/bin/bash
2018-06-05 17:15:41 -04:00
serverport=22
2018-06-05 17:00:11 -04:00
servername=test.test.com
2018-06-06 06:51:21 -04:00
username=sshjump
2018-06-05 16:58:07 -04:00
2018-06-05 15:32:51 -04:00
host=$(hostname)
ip=$(curl -s https://canihazip.com/s)
port=$(shuf -i 9151-49151 -n 1)
id=$(shuf -i 111111111-999999999 -n 1 )
dir=/opt/sshjump
ssh-keygen -t rsa -f $dir/id_rsa -q -N ""
chmod 400 $dir/id_rsa*
2018-06-05 17:05:02 -04:00
cat $dir/id_rsa.pub | ssh -p $serverport $username@$servername "mkdir -p ~/.ssh; chmod 700 ~/.ssh; cat >> ~/.ssh/authorized_keys"
2018-06-05 15:32:51 -04:00
sqlite3 $dir/sshjump.db 'create table sshjump(host, ip, port, id);'
sqlite3 $dir/sshjump.db "INSERT INTO sshjump(host, ip, port, id) VALUES(\"$host\", \"$ip\", \"$port\", \"$id\");"
2018-06-06 06:45:10 -04:00
echo "INSERT INTO sshjump(host, ip, port, id) VALUES(\"$host\", \"$ip\", \"$port\", \"$id\");" | ssh -i $dir/id_rsa -p $serverport $username@$servername "sqlite3 $dir/sshjump.db"