From 58f75cd799cefa86a378a78599710de0099cb86a Mon Sep 17 00:00:00 2001 From: hc Date: Wed, 2 Oct 2024 11:15:50 +0800 Subject: added ssh agrent forwarding --- git/set-global_git-ssh-wrapper.sh | 33 +++++++++++++++++++++++++++++++++ git/set-global_user.sh | 2 ++ git/tools/git-ssh-wrapper.sh | 2 ++ 3 files changed, 37 insertions(+) create mode 100755 git/set-global_git-ssh-wrapper.sh create mode 100755 git/set-global_user.sh create mode 100755 git/tools/git-ssh-wrapper.sh (limited to 'git') diff --git a/git/set-global_git-ssh-wrapper.sh b/git/set-global_git-ssh-wrapper.sh new file mode 100755 index 0000000..e851f1b --- /dev/null +++ b/git/set-global_git-ssh-wrapper.sh @@ -0,0 +1,33 @@ +#!/bin/bash + +if ! sudo grep -q "^AllowAgentForwarding yes" /etc/ssh/sshd_config; then + echo "AllowAgentForwarding not set. Adding it to sshd_config..." + echo "AllowAgentForwarding yes" | sudo tee -a /etc/ssh/sshd_config > /dev/null + echo "Added AllowAgentForwarding yes to /etc/ssh/sshd_config" +else + echo "AllowAgentForwarding is already set to yes in /etc/ssh/sshd_config" +fi +# this should be enabled on both client and server + +# Get the directory of this script +SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )" + +# Path to the git-ssh-wrapper.sh +WRAPPER_PATH="$SCRIPT_DIR/tools/git-ssh-wrapper.sh" + +# Check if the wrapper script exists +if [ ! -f "$WRAPPER_PATH" ]; then + echo "Error: git-ssh-wrapper.sh not found at $WRAPPER_PATH" + exit 1 +fi + +# Make sure the wrapper script is executable +chmod +x "$WRAPPER_PATH" + +# Set the global Git SSH command +git config --global core.sshCommand "$WRAPPER_PATH" + +echo "Git SSH command has been set to use $WRAPPER_PATH" +echo "You can verify this by running: git config --global --get core.sshCommand" + +#ssh-agent bash -c 'ssh-add ~/key && ssh -A -p24 user@code.server' diff --git a/git/set-global_user.sh b/git/set-global_user.sh new file mode 100755 index 0000000..30e11eb --- /dev/null +++ b/git/set-global_user.sh @@ -0,0 +1,2 @@ +git config --global user.email "hc@email.ch" +git config --global user.name "hc" diff --git a/git/tools/git-ssh-wrapper.sh b/git/tools/git-ssh-wrapper.sh new file mode 100755 index 0000000..dc23334 --- /dev/null +++ b/git/tools/git-ssh-wrapper.sh @@ -0,0 +1,2 @@ +#!/bin/bash +ssh -v -A -o ForwardAgent=yes "$@" -- cgit v1.2.3-70-g09d2