Shell
#!/bin/sh | |
| |
if [ "$1" = "-h" ]; then | |
# help message | |
echo "usgage: $(basename $0) [-h|-s|-x]" | |
echo " -h: help message" | |
echo " -s: start daemon" | |
echo " -x: kill daemon" | |
exit 0 | |
| |
elif [ "$1" = "-s" ]; then | |
# generate keys | |
for type | |
[ -f /etc/ssh/ssh_host_dsa_key ] || ssh-keygen -t dsa -N "" -f /etc/ssh/ssh_host_dsa_key | |
[ -f /etc/ssh/ssh_host_ecdsa_key ] || ssh-keygen -t ecdsa -N "" -f /etc/ssh/ssh_host_ecdsa_key | |
[ -f /etc/ssh/ssh_host_ed25519_key ] || ssh-keygen -t ed25519 -N "" -f /etc/ssh/ssh_host_ed25519_key | |
[ -f /etc/ssh/ssh_host_rsa_key ] || ssh-keygen -t rsa -N "" -f /etc/ssh/ssh_host_rsa_key | |
| |
# start daemon | |
ps aux | grep -q sshd || /bin/sshd | |
| |
elif [ "$1" = "-x" ]; then | |
# kill daemon | |
kill -9 $(ps aux | awk '/sshd/ {print $1}') | |
| |
elif [ "$1" = "" ]; then | |
# status | |
ps aux | awk '/sshd/ {print}' | |
| |
else | |
# error | |
echo "unknown argument ($1)" | |
exit 1 | |
fi |