【问题标题】:.ssh directory not being created.ssh 目录未创建
【发布时间】:2013-02-17 21:10:02
【问题描述】:

要生成.ssh 目录,我使用以下命令:

ssh-keygen

取自本教程:http://ebiquity.umbc.edu/Tutorials/Hadoop/05%20-%20Setup%20SSHD.html

但是.ssh 目录没有创建,所以当我使用cd ~/.ssh 时,我得到了这个错误:

"no such file or directory"

是否缺少步骤?使用ssh-keygen 命令时是否应该创建.ssh 目录?

【问题讨论】:

    标签: unix ssh cygwin


    【解决方案1】:

    作为对其他答案的轻微改进,您可以使用mkdir 的-m 开关将mkdir 和chmod 作为单个操作执行。

    $ mkdir -m 700 ${HOME}/.ssh
    

    用法

    来自 Linux 系统

    $ mkdir --help
    Usage: mkdir [OPTION]... DIRECTORY...
    Create the DIRECTORY(ies), if they do not already exist.
    
    Mandatory arguments to long options are mandatory for short options too.
      -m, --mode=MODE   set file mode (as in chmod), not a=rwx - umask
    ...
    ...
    

    【讨论】:

      【解决方案2】:

      是否缺少步骤?

      是的。您需要创建目录:

      mkdir ${HOME}/.ssh
      

      此外,SSH 要求您设置权限,以便只有您(所有者)可以访问 ~/.ssh 中的任何内容:

      % chmod 700 ~/.ssh
      

      使用ssh-keygen命令时是否应该生成.ssh目录?

      没有。此命令会生成一个 SSH 密钥对,但如果它无法写入所需的目录,则会失败:

      % ssh-keygen
      Generating public/private rsa key pair.
      Enter file in which to save the key (/Users/xxx/.ssh/id_rsa): /Users/tmp/does_not_exist
      Enter passphrase (empty for no passphrase): 
      Enter same passphrase again: 
      open /Users/tmp/does_not_exist failed: No such file or directory.
      Saving the key failed: /Users/tmp/does_not_exist.
      

      一旦您创建了密钥,您还应该限制只有您自己可以读取这些密钥文件:

      % chmod -R go-wrx ~/.ssh/*
      

      【讨论】:

      • 你忘了告诉读者设置.ssh的权限
      • @Shrewmouse:已修复
      • chmod -R go-wrx 假设该目录的权限已为所有者设置了 rwx。 chmod -R 700 是万无一失的。即使您解决了这个问题,最后,您的答案也是已接受答案的子集。您也许应该删除您的答案。
      • @Shrewmouse:我认为这是对新创建的目录的完全合理的假设。到底谁会希望~/.ssh/id_rsa 成为可执行?
      • ~/.ssh/id_rsa 在您的工作流程中此时不存在,因此您的观点没有实际意义。假设您可以用更少的字符明确表示永远是不合理的。 chmod 700 胜过 chmod go-wrx,因为它是明确的。如果你喜欢使用 'rwx 和 'ugo' 那么chmod u+rwx ~/.ssh; chmod go-rwx ~/.ssh
      【解决方案3】:

      我假设你有足够的权限来创建这个目录。

      要解决您的问题,您可以 ssh 到其他位置:

      ssh user@some.host
      

      并接受新密钥 - 它将在下面创建目录 ~/.ssh 和 known_hosts,或者直接使用手动创建它

      mkdir ~/.ssh
      chmod 700 ~/.ssh
      

      注意chmod 700是重要的一步!

      之后,ssh-keygen 应该可以正常工作了。

      【讨论】:

      • 我在chroot里面,它不能(也不能)创建“/.ssh/”目录,我想给ssh命令一个不同的目录,在这种情况下“ /私人/.ssh”。我没有env,设置set HOME=/private/ 不起作用。有什么想法吗?
      • 授权密钥应该是 chmod 600 否则对我来说不起作用。
      • 谁应该拥有它?用户及其所属组?
      猜你喜欢
      • 2012-09-04
      • 1970-01-01
      • 2016-09-19
      • 2023-03-07
      • 2019-11-03
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多