将SSH密钥保存在home而不是root中


1

当我尝试使用创建SSH密钥时 sudo ssh-keygen -t rsa 我收到了请求:

Enter file in which to save the key (/root/.ssh/id_rsa):

但是,我希望保存文件 /home/user2/.ssh/id_rsa。当我进入该目录时,我收到此错误:

Saving key "/home/user2/.ssh/id_rsa" failed: No such file or directory

任何进入不同目录的尝试都会返回错误。

我怎样才能生成密钥 /home/user2/.ssh/id_rsa

编辑:当我删除 sudo 我遇到这个问题:

Generating public/private rsa key pair.
Enter file in which to save the key (/home/hduser/.ssh/id_rsa): 
Enter passphrase (empty for no passphrase): 
Enter same passphrase again: 
Saving key "/home/hduser/.ssh/id_rsa" failed: Not a directory

但是不应该SSH创建目录?


是目录吗? /home/user2/.ssh/ 存在?
Kamil Maciorowski

1
你为什么这么称呼它 sudo 首先?
gronostaj

@KamilMaciorowski我以为.ssh会自动创建吗?
steve zissou

@gronostaj我不确定,我从导游那里得到它,我会编辑我的问题,每当我不使用时给出输出 sudo
steve zissou

Answers:


1

当我尝试使用创建SSH密钥时 sudo ssh-keygen -t rsa 我收到了请求:

Enter file in which to save the key (/root/.ssh/id_rsa):

通过使用 sudo 你要求在另一个帐户下运行该程序 ,特别是root。所以keygen将以root身份运行,创建一个属于root的密钥,当然它将使用root的主目录来存储该密钥。

要创建属于您自己的文件(并使用您自己的路径等),请不要使用 sudo

如果不使用 sudo 导致奇怪的权限错误,更好地调查和修复 - 如果你只是他们不会悄悄地修复自己 sudo 整个东西;经常这会让事情变得更糟。

当我删除sudo时,我遇到了这个问题:

Generating public/private rsa key pair.
Enter file in which to save the key (/home/hduser/.ssh/id_rsa): 
Enter passphrase (empty for no passphrase): 
Enter same passphrase again: 
Saving key "/home/hduser/.ssh/id_rsa" failed: Not a directory

但是不应该SSH创建目录?

这应该。但错误信息的真正含义是什么 /home/hduser/.ssh 已经存在 - 它只是一个目录而已。 它可能是文件,破坏的符号链接,文件的符号链接等。

再次:调查情况。看什么 .ssh 实际上是,跑 ls -ld 在上面。如有必要,重命名文件/链接/项目或完全删除它。


谢谢!我删除文件时它工作。顺便问一下 ls -ld 告诉我文件究竟是什么。不是 . 在文件名前面告诉我它的隐藏目录?
steve zissou

没有 . 在文件名前面只告诉你它是隐藏的 某物 ,但不以任何方式暗示它是一个目录。实际项目类型是ls -l输出的第一个字符(在权限指示符之前)。
grawity
By using our site, you acknowledge that you have read and understand our Cookie Policy and Privacy Policy.
Licensed under cc by-sa 3.0 with attribution required.