sudo -H -u git gitosis-init< 〜/ id_rsa.pub |错误:没有这样的文件或目录

时间:2016-06-10 02:01:57

标签: linux git bash

  

我从博客上获得了关于如何为git配备gitosis的shell脚本。   但是在运行脚本后我得到了“没有这样的文件或目录”错误。

[git@209285 ~]$ sudo -H -u git gitosis-init < ~/id_rsa.pub
Traceback (most recent call last):
  File "/usr/local/bin/gitosis-init", line 9, in <module>
    load_entry_point('gitosis==0.2', 'console_scripts', 'gitosis-init')()
  File "/usr/local/lib/python2.7/site-packages/gitosis-0.2-py2.7.egg/gitosis/app.py", line 24, in run
    return app.main()
  File "/usr/local/lib/python2.7/site-packages/gitosis-0.2-py2.7.egg/gitosis/app.py", line 38, in main
    self.handle_args(parser, cfg, options, args)
  File "/usr/local/lib/python2.7/site-packages/gitosis-0.2-py2.7.egg/gitosis/init.py", line 138, in handle_args
    user=user,
  File "/usr/local/lib/python2.7/site-packages/gitosis-0.2-py2.7.egg/gitosis/init.py", line 75, in init_admin_repository
    template=resource_filename('gitosis.templates', 'admin')
  File "/usr/local/lib/python2.7/site-packages/gitosis-0.2-py2.7.egg/gitosis/repository.py", line 63, in init
    close_fds=True,
  File "/usr/local/lib/python2.7/subprocess.py", line 522, in call
    return Popen(*popenargs, **kwargs).wait()
  File "/usr/local/lib/python2.7/subprocess.py", line 710, in __init__
    errread, errwrite)
  File "/usr/local/lib/python2.7/subprocess.py", line 1335, in _execute_child
    raise child_exception
OSError: [Errno 2] No such file or directory

我很困惑,正如男人手册所说:

  -H          The -H (HOME) option sets the HOME environment variable to the homedir of the target user (root by default) as specified in passwd(5).  By default, sudo
           does not modify HOME (see set_home and always_set_home in sudoers(5)).

,引自linux手册。

-H选项只是将HOME环境变量设置为passwd中指定的目标用户的homedir。

但是我在/ etc / passwd文件中为git用户指定了“/ home / git”作为homedir。

apache:x:48:48:Apache:/var/www:/sbin/nologin
git:x:100:101:git version control:/home/git:/bin/bash
duanduan:x:101:500::/home/duanduan:/bin/bash

但为什么我仍然收到这条消息?或者我对手册中描述的理解不正确?

附加评论

似乎之前指定了绝对路径。也许,这不是原因。

 sudo -H -u git gitosis-init < /home/git/id_rsa.pub
Traceback (most recent call last):
  File "/usr/local/bin/gitosis-init", line 9, in <module>
    load_entry_point('gitosis==0.2', 'console_scripts', 'gitosis-init')()
  File "/usr/local/lib/python2.7/site-packages/gitosis-0.2-py2.7.egg/gitosis/app.py", line 24, in run
    return app.main()
  File "/usr/local/lib/python2.7/site-packages/gitosis-0.2-py2.7.egg/gitosis/app.py", line 38, in main
    self.handle_args(parser, cfg, options, args)
  File "/usr/local/lib/python2.7/site-packages/gitosis-0.2-py2.7.egg/gitosis/init.py", line 138, in handle_args
    user=user,
  File "/usr/local/lib/python2.7/site-packages/gitosis-0.2-py2.7.egg/gitosis/init.py", line 75, in init_admin_repository
    template=resource_filename('gitosis.templates', 'admin')
  File "/usr/local/lib/python2.7/site-packages/gitosis-0.2-py2.7.egg/gitosis/repository.py", line 63, in init
    close_fds=True,
  File "/usr/local/lib/python2.7/subprocess.py", line 522, in call
    return Popen(*popenargs, **kwargs).wait()
  File "/usr/local/lib/python2.7/subprocess.py", line 710, in __init__
    errread, errwrite)
  File "/usr/local/lib/python2.7/subprocess.py", line 1335, in _execute_child
    raise child_exception
OSError: [Errno 2] No such file or directory

1 个答案:

答案 0 :(得分:2)

我想这是因为~在转移到sudo作为参数之前被bash扩展,为什么不尝试为公钥文件指定绝对路径?