Last active
May 4, 2017 07:43
-
-
Save zjx20/e744ebe74c5ac6aef35d9e0a1ef7935c to your computer and use it in GitHub Desktop.
A wrapper for enabling "SSH agent forwarding" for ssh command
This file contains hidden or 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/bash | |
# Usage: | |
# 1. save this gist to some where | |
# 2. update your ssh command, like: | |
# /path/to/ssh-agent-for-github.sh ssh -A user@your-server | |
# 3. you should able to access github with your ssh key now, try "ssh -T [email protected]" to confirm it | |
# NOTICE: you may want to change this value! | |
GITHUB_SSH_KEY=~/.ssh/my_github_rsa | |
CURRENT_DIR=$(cd "$(dirname "$0")"; pwd) | |
pushd "${CURRENT_DIR}" > /dev/null 2>&1 | |
ssh_agent_started=0 | |
if [ -f '.ssh-agent-env' ]; then | |
source .ssh-agent-env | |
fi | |
if [ -n "${SSH_AGENT_PID}" ]; then | |
if [ `pgrep ssh-agent | grep "${SSH_AGENT_PID}" | wc -l` = "1" ]; then | |
# A valid ssh-agent has been started | |
ssh_agent_started=1 | |
else | |
echo "Process ${SSH_AGENT_PID} is not exist." | |
fi | |
fi | |
if [ "${ssh_agent_started}" = "0" ]; then | |
ssh-agent > .ssh-agent-env | |
source .ssh-agent-env | |
ssh-add -k "${GITHUB_SSH_KEY}" | |
# ssh-add -l | |
fi | |
popd > /dev/null 2>&1 | |
exec "$@" |
This file contains hidden or 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/bash | |
# This script is used to replace the ssh command in order to let you do `git commit` | |
# on the server without getting the "Please tell me who you are" error, by forwarding env vars. | |
# | |
# Usage: | |
# 1. append an AcceptEnv line to /etc/ssh/sshd_config on the server, and then restart the sshd | |
# AcceptEnv GIT_AUTHOR_NAME GIT_AUTHOR_EMAIL GIT_COMMITTER_NAME GIT_COMMITTER_EMAIL | |
# 2. save this gist to the same place as ssh-agent-for-github.sh | |
# 3. update your ssh command, like: | |
# /path/to/ssh-wrapper-for-github.sh user@your-server | |
GIT_USER=your_github_username | |
[email protected] | |
CURRENT_DIR=$(cd "$(dirname "$0")"; pwd) | |
GIT_AUTHOR_NAME="${GIT_USER}" GIT_AUTHOR_EMAIL="${GIT_EMAIL}" \ | |
GIT_COMMITTER_NAME="${GIT_USER}" GIT_COMMITTER_EMAIL="${GIT_EMAIL}" \ | |
"${CURRENT_DIR}"/ssh-agent-for-github.sh ssh -A -o "SendEnv=GIT_COMMITTER_*" -o "SendEnv=GIT_AUTHOR_*" "$@" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment