为Git存储库启用ident字符串,可以通过以下步骤实现:
#!/bin/sh
IDENT_USER="git"
IDENT_PORT="113"
if [ -n "$(which ident)" ]; then
# Get the IP address of the remote client
CLIENT_IP=$(echo $SSH_CONNECTION | cut -d ' ' -f 1)
# Query the ident server for the user's identity
IDENT_RESPONSE=$(echo | ident -q $IDENT_PORT $CLIENT_IP 2>/dev/null)
# Extract the username from the ident response
IDENT_USER=$(echo $IDENT_RESPONSE | cut -d ':' -f 2)
fi
# Update the Git repository with the user's identity
export GIT_COMMITTER_NAME="$IDENT_USER"
export GIT_COMMITTER_EMAIL="$IDENT_USER@example.com"
chmod +x post-update
service sshd restart
Host example.com
IdentitiesOnly yes
IdentityFile ~/.ssh/id_rsa
其中,example.com是Git服务器的域名,~/.ssh/id_rsa是客户端的SSH私钥文件。
需要注意的是,使用ident字符串进行身份验证存在一定的安全风险,因此应该在受信任的网络环境中使用。此外,ident2服务在某些Linux发行版中可能不被默认安装,需要手动安装。
没有搜到相关的沙龙
领取专属 10元无门槛券
手把手带您无忧上云