Skip to content

Instantly share code, notes, and snippets.

@pstjuste
Last active December 15, 2018 18:45
Show Gist options
  • Save pstjuste/7365293 to your computer and use it in GitHub Desktop.
Save pstjuste/7365293 to your computer and use it in GitHub Desktop.
These are a bunch of small scripts that I use, I figured it would be better to have them publicly as gists :)
# create certificate
openssl rsa -in old.key -des3 -out new.key
openssl pkcs12 -export -chain -in old.crt -inkey new.key -CAfile ca.crt -out new.p12
# self sign certificate
openssl req \
-x509 -nodes -days 365 \
-newkey rsa:1024 -keyout mycert.pem -out mycert.pem
# clear chromeos partition
sudo echo 'clobber' > /mnt/stateful_partition/.update_available
#sudo nmcli nm wifi off
sudo rfkill unblock wlan
sleep 3
sudo sysctl -w net.ipv4.ip_forward=1
sudo ifconfig wlan0 192.168.10.1/24 up
sudo iptables -t nat -A POSTROUTING -o usb0 -j MASQUERADE
exec sudo hostapd /etc/hostapd/hostapd.conf
# allow ssh in iptables
/sbin/iptables -A INPUT -p tcp --dport 22 -j ACCEPT
#!/bin/bash
#identity file
id=$1
#userid
user=$2
#list of nodes
list=$3
# no of threads
thread_count=$4
#cmd
cmd=$5
# Check input arguments
if [[ $# -lt 5 ]]; then
echo "usage: $0 <id file> <username> <host list> <thread count> <cmd>"
exit 1
fi
# Cleanout old directories
if [[ -d stdout ]]; then
rm -rf stdout
fi
if [[ -d stderr ]]; then
rm -rf stderr
fi
mkdir stdout
mkdir stderr
mv ~/.ssh/known_hosts ~/.ssh/known_hosts.bak
# Set necessary variables
sleep_time=5
TIME="date +%s"
start_time=$(${TIME})
# Loop through list of nodes
for host in $(< ${list}); do
# Checks to see if appropriate number of threads are running
while [[ $(jobs -p | wc -l) -gt $(( ${thread_count} - 1 )) ]]; do
sleep ${sleep_time}
done
# Run remote command via ssh
ssh -n -x -o StrictHostKeyChecking=no -o HostbasedAuthentication=no \
-o CheckHostIP=no -o ConnectTimeout=15 -o PasswordAuthentication=no \
-o ServerAliveCountMax=3 -o ServerAliveInterval=15 -o BatchMode=yes \
-i ${id} -l ${user} ${host} "$cmd" 1>stdout/${host} 2>stderr/${host} &
done
# Wait for all background processes to finish
wait
mv ~/.ssh/known_hosts.bak ~/.ssh/known_hosts
# Print total time and exit code
end_time=$(${TIME})
(( total = ${end_time} - ${start_time} ))
echo "Parallel ssh took ${total} seconds and return ${exit_code}"
# how to run ssh on chromeos dev
# run following as root
mkdir -m 0711 /mnt/stateful_partition/etc/ssh
cd /mnt/stateful_partition/etc/ssh
ssh-keygen -t rsa -f ssh_host_rsa_key
ssh-keygen -t dsa -f ssh_host_dsa_key
ssh-keygen -t dsa -f ssh_host_dsa_key
ssh-keygen -t ed25519 -f ssh_host_ed25519_key
/usr/sbin/sshd
iptables -I INPUT -p tcp --dport 22 -j ACCEPT
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment