本文介绍了通过SSH git push设置环境变量的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述 29岁程序员,3月因学历无情被辞! 我正在阅读Scott Chacon的Git书,只想确认一下。这部分:没有关于如何完成的指示,但 gitolite (一个基于perl的授权层,非常需要用户认证的id)使用 ssh forced command :每个公钥在〜git / .ssh中/ authorized_keys 包含对包含用户标识参数的包装器脚本的调用。 该脚本将: 执行git命令 失败,如果这个命令是别的,但是一个git命令 在〜git / .ssh / authorized_keys 中,您没有只是公钥,但是通话作为参数的用户ID的包装器: command =/ wrapper / script userid,无端口转发,no-X11-for ward,no-agent-forwarding,no-pty ssh-rsa AAAAB3N ... ^^^^^^^^^^^^^^ (强制命令) 您可以在 src / gitolite-shell#L102-L108 。 I'm reading Scott Chacon's Git book, and just wanted to confirm something. This part:I presume that it's required for the pusher to install a script wrapping around the ssh command. For example, the script would perhaps set the GIT_SSH or GIT_SSH_COMMAND environment variable to point to a shell script that may have something like#!/bin/bashHOST=$1shiftssh -i ~/.ssh/id_rsa $HOST USER=foo $@Now anytime a git push is done and the remote contains an ssh url, it will invoke that script and update the refs while passing the USER environment variable.The other way would be to use "SendEnv USER" in ~/.ssh/config on the local machine and "AcceptEnv USER" in /etc/ssh/sshd_config on the remote git server.Any other ways that come to mind that expand on the part in bold? I'm particularly looking for a way that doesn't require the pusher to do much work in regards to configuring his environment. Assume everyone's running some form of Windows and needs to setup ssh through some Unix emulator like Cygwin. 解决方案 This example is not about the shell or the ssh command.It is taken from the "Server-Side Hook" section, and describe how to tailored the update hook based on the user (authenticated through ssh)There is no indication on how this is done, but gitolite (a perl-based authorization layer, which very much needs the user authenticated id) is using ssh forced command: each public key in the ~git/.ssh/authorized_keys include the call to a wrapper script which takes in parameters the user id.That script will:execute the git commandfails if this the command is anything else but a git commandIn the ~git/.ssh/authorized_keys, you don't have just the public key, but the call to the wrapper with the user id as a parameter:command="/wrapper/script userid",no-port-forwarding,no-X11-for warding,no-agent-forwarding,no-pty ssh-rsa AAAAB3N... ^^^^^^^^^^^^^^^ (forced command)You can see the environment variable being set by the (gitolite here) wrapper script in src/gitolite-shell#L102-L108. 这篇关于通过SSH git push设置环境变量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持! 上岸,阿里云!
08-05 12:42