创建 ssh 公钥并使用 ssh-copy-id 复制失败

创建 ssh 公钥并使用 ssh-copy-id 复制失败

我正在尝试设置 ssh 公钥配置,以便通过 fstab 将 sftp 共享从我的服务器安装到我的笔记本电脑上。我已遵循了很多说明,我相信我已正确完成所有操作,但 ssh-copy-id 命令一直失败,告诉我 id_rsa.pub 文件不存在。

这里我在我的服务器上创建密钥:

(base) chuff@jan:~$ ssh-keygen  
Generating public/private rsa key pair.  
Enter file in which to save the key (/home/chuff/.ssh/id_rsa):   
/home/chuff/.ssh/id_rsa already exists.  
Overwrite (y/n)? y  
Enter passphrase (empty for no passphrase):   
Enter same passphrase again:   
Your identification has been saved in /home/chuff/.ssh/id_rsa  
Your public key has been saved in /home/chuff/.ssh/id_rsa.pub  

这是我的 ssh 文件夹的内容:

(base) chuff@jan:~/.ssh$ ls -la ~/.ssh/  
total 32  
drwx------  2 chuff chuff 4096 Jan  3 15:42 .  
drwxr-x--- 41 chuff chuff 4096 Jan  3 15:15 ..  
-rw-r--r--  1 chuff chuff 2590 Jan  3 16:43 id_rsa  
-rw-r--r--  1 chuff chuff  563 Jan  3 16:43 id_rsa.pub  
-rw-r--r--  1 chuff chuff  728 Aug  3 13:21 known_hosts  
-rw-r--r--  1 chuff chuff  506 Aug  3 13:21 known_hosts.old  
-rw-r--r--  1 chuff chuff 2590 Jan  3 15:17 my.key  
-rw-r--r--  1 chuff chuff  563 Jan  3 15:17 my.key.pub  

以上所有内容均在我的服务器上执行。

当我尝试在笔记本电脑上运行 ssh-copy-id 时,出现以下信息:

chuff@osmc:~/.ssh$ ssh-copy-id -i /home/chuff/.ssh/id_rsa.pub [email protected]  
/usr/bin/ssh-copy-id: ERROR: failed to open ID file '/home/chuff/.ssh/id_rsa.pub': No such file  

我可以从我的笔记本电脑远程登录到我的服务器,所以我知道我可以进入它:

chuff@osmc:~/.ssh$ telnet 192.168.0.3 22  
Trying 192.168.0.3...  
Connected to 192.168.0.3.  
Escape character is '^]'.  
SSH-2.0-OpenSSH_8.9p1 Ubuntu-3ubuntu0.5  

如果我尝试通过 ssh 连接,我会得到以下信息:

chuff@osmc:~/.ssh$ ssh -vv [email protected]  
OpenSSH_8.4p1 Debian-5+deb11u2, OpenSSL 1.1.1w  11 Sep 2023  
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  
debug1: /etc/ssh/ssh_config line 21: Applying options for *  
debug2: resolve_canonicalize: hostname 192.138.0.3 is address  
debug2: ssh_connect_direct  
debug1: Connecting to 192.138.0.3 [192.138.0.3] port 22.  

并且不再进一步发展。

这确实让我很头疼。

如果有人能帮忙我将非常感激。

谢谢。

相关内容