Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/ssh/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ubuntu 如何将ssh指向配置文件_Ubuntu_Ssh - Fatal编程技术网

Ubuntu 如何将ssh指向配置文件

Ubuntu 如何将ssh指向配置文件,ubuntu,ssh,Ubuntu,Ssh,我只是切换了本地系统,所以我必须使用ssh密钥再次回到服务器。我通常使用sshdavid@server进入。但是由于我已经切换到新机器,所以进入服务器的唯一方法是ssh-ipath/to/id\u rsa\u服务器david@0.0.0.0它指向我机器上的私钥 现在我已经在.ssh文件夹中设置了一个配置文件,这是我从上一台机器复制的。该文件的外观如下所示: Host server Hostname 0.0.0.0 User david IdentityFile ~/.ss

我只是切换了本地系统,所以我必须使用ssh密钥再次回到服务器。我通常使用
sshdavid@server
进入。但是由于我已经切换到新机器,所以进入服务器的唯一方法是
ssh-ipath/to/id\u rsa\u服务器david@0.0.0.0
它指向我机器上的私钥

现在我已经在
.ssh
文件夹中设置了一个配置文件,这是我从上一台机器复制的。该文件的外观如下所示:

Host server
    Hostname 0.0.0.0
    User david
    IdentityFile ~/.ssh/id_rsa_server

如何让ssh系统再次识别配置文件?

通常,ssh将从
~/.ssh/config
或从
/etc/ssh/config
全局获取配置

要测试:

  • 在ssh中使用
    -v
    标志查看配置文件是否已加载。如评论所示,您可以使用附加的
    v
    s(如
    -vvv
    )来增加详细性
  • 检查
    .ssh/config
    上的所有者和权限。目录权限应为700,并检查所有权。步骤1可能会给出提示
  • 使用
    -F
    启动
    ssh
    ,查看是否存在问题

  • 上面的项目应该确认权限、路径和文件位置。

    运行
    ssh时会出现什么错误/消息david@server
    ?还要检查
    ~/.ssh/config
    文件的权限是否为
    600
    ssh:无法解析主机名服务器:名称或服务未知
    ,权限设置是否正确除非您编辑主机名,否则错误消息似乎表明配置文件的
    主机名clearpath
    为值。这似乎不正确,还是我遗漏了什么?您以前的系统是否将
    clearpath
    映射到
    /etc/hosts
    中的服务器IP地址?否则我怀疑它是可以解决的。不,它没有。在这个系统上,
    /etc/hosts
    文件是空的。我假设配置文件将处理路由,等等,但是由于某种原因,它没有看到配置文件(我假设)。哦,你的意思是
    clearpath
    是你给ssh主机的别名,对吗?如果是这样的话,我现在明白你的意思了。尝试更详细地运行ssh命令,并强制它读取配置文件,即:
    ssh-vvv-F~/.ssh/configdavid@...
    ?这非常有帮助。谢谢我还没有解决它。但是,我发现它看到了配置文件,但配置文件没有看到密钥。给出者:
    debug1:identity file/home/david/.ssh/id\u rsa\u clearpath type 0 debug1:key\u load\u public:没有这样的文件或目录
    看起来您的配置文件指向id文件位置,但可能存储在其他位置。很高兴这很有帮助!这些权限(至少对于
    .ssh/config
    )有效。如果使用
    -v
    没有投诉,则权限不是问题所在。如果您所说的有效命令不是
    ssh-i~/.ssh/id\u rsa\u serverdavid@0.0.0.0
    如果上面列出的ssh配置正确,也应该给出一个线索。确定。谢谢你的帮助!
    user@pc:~$ ssh -v server
    OpenSSH_8.2p1 Ubuntu-4, OpenSSL 1.1.1f  31 Mar 2020
    debug1: Reading configuration data /home/user/.ssh/config
    debug1: /home/user/.ssh/config line 1: Applying options for server
    debug1: Reading configuration data /etc/ssh/ssh_config
    debug1: /etc/ssh/ssh_config line 19: include /etc/ssh/ssh_config.d/*.conf matched no files
    
    user@pc:~$ ls -ld --  .ssh*/
    drwx------ 2 user user 4096 May 25 23:05 .ssh/
    user@pc:~$ ls -la .ssh/config
    -rw-rw-r-- 1 user user 39 May 25 23:05 .ssh/config
    
    user@pc:~$ ssh -v -F ~/.ssh/config