Created
July 15, 2016 06:21
-
-
Save nikuyoshi/08d20662993f53156be79f05d9d5515d to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/sh | |
####################################################### | |
# | |
# Precondition: Complete executing the following command | |
# ssh-keygen -t rsa | |
# | |
# How to use: | |
# sh ssh-auto-auth.sh {user name}@{IP address} | |
# | |
# ex. sh ssh-auto-auth.sh [email protected] | |
# | |
# FYI: | |
# http://www.linuxproblem.org/art_9.html | |
# | |
####################################################### | |
if [ $# -lt 1 -o $# -gt 1 ]; then | |
echo -e "How to use: sh ssh-auto-auth.sh {user name}@{IP address}" | |
exit 1 | |
fi | |
# Use ssh to create a directory ~/.ssh as user b on B. (The directory may already exist, which is fine). | |
ssh "$1" mkdir -p .ssh | |
if [ $? -ne 0 ]; then | |
echo -e "Failed to create .ssh directory." | |
exit 1 | |
fi | |
# Append a's new public key to b@B:.ssh/authorized_keys and enter b's password one last time. | |
cat ~/.ssh/id_rsa.pub | ssh "$1" 'cat >> .ssh/authorized_keys' | |
if [ $? -ne 0 ]; then | |
echo -e "Failed to append new public key to authorized_keys" | |
exit 1 | |
fi | |
echo "Complete!" | |
exit 0 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment