【问题标题】:How to insert SSH key on a Git server (git-shell access only)如何在 Git 服务器上插入 SSH 密钥(仅限 git-shell 访问)
【发布时间】:2016-07-05 01:58:18
【问题描述】:

我想将我的 SSH 密钥添加到 git 服务器(公司服务器)上的授权密钥中,这样每次推送时都不必输入密码。但是由于某种原因,我无法使其正常工作。

我尝试了什么:

ssh-copy-id user@server
/usr/bin/ssh-copy-id: INFO: attempting to log in with the new key(s), to filter out any that are already installed
/usr/bin/ssh-copy-id: INFO: 1 key(s) remain to be installed -- if you are prompted now it is to install the new keys
user@server's password: 
fatal: unrecognized command '
        umask 077 ;
        mkdir -p .ssh && cat >> .ssh/authorized_keys || exit 1 ;
        if type restorecon >/dev/null 2>&1 ; then restorecon -F .ssh .ssh/authorized_keys ; fi'

当我尝试 ssh 到 git 服务器时,我得到以下响应:

fatal: Interactive git shell is not enabled.
hint: ~/git-shell-commands should exist and have read and execute access.

显然用户帐户正在使用git-shell,它似乎不理解通常的shell命令。

是否仍然可以以某种方式将公共 SSH 密钥添加到 git 服务器用户帐户?是否有一些 git 命令可以让我将我的公共 SSH 密钥添加到列表中?

我对 git 服务器的唯一访问是通过命令行,并且 GitWeb 界面正在运行(但在那里我也看不到任何安装 SSH 密钥的选项)。

【问题讨论】:

  • 如果您只获得了 git-shell 访问权限,我想您将无法添加 ssh 密钥。您与公司的系统管理员/服务器维护人员谈过吗?
  • 还没有,我试着先弄清楚这一点。但似乎没有其他选择,所以我会与他们核实。

标签: git ssh-keys git-shell


【解决方案1】:

你应该联系你的系统管理员,确保用户主目录权限没有其他人的写权限。

对于/home/user/.ssh 的权限建议是使用0700/home/user/authorized_keys 权限作为其组和所有者本身0600

我假设user 组是git

# cd /home/user
# chown -R user:git  .ssh
# chmod 0700 .ssh
# chmod 0600 .ssh/authorized_keys

如果此文件(.ssh/authorized_keys)、~/.ssh directory 或用户的主目录可由其他用户写入,则该文件可能被未经授权的用户修改或替换。在这种情况下,sshd 将不允许使用它,除非 StrictModes 选项已设置为“no”。

更多信息见man 8 sshd

【讨论】:

  • 我认为这个问题与.ssh 的权限无关。这是git-shell 不允许执行该特定命令。
猜你喜欢
  • 2014-12-06
  • 2019-12-07
  • 2020-11-17
  • 2015-08-31
  • 1970-01-01
  • 2021-11-29
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多