目录结构
免密登录相关文件放在~/.ssh目录下,主要有4个文件。
[root@linux1 .ssh]# pwd
/root/.ssh
[root@linux1 .ssh]# ll
total 16
-rw-r--r--. 1 root root 393 May 21 04:48 authorized_keys
-rw-r--r--. 1 root root 0 May 21 05:05 config
-rw-------. 1 root root 1675 May 21 04:17 id_rsa
-rw-r--r--. 1 root root 393 May 21 04:17 id_rsa.pub
-rw-r--r--. 1 root root 396 May 21 04:21 known_hosts
[root@linux1 .ssh]#
authorized_keys:存想免密登录机器的公钥
id_rsa:私钥 ##rsa、dsa:加密类型
id_rsa.pub:公钥
known_hosts:记录访问过本机的ip和公钥
config:可以配置忽略known_hosts记录等
生成步骤
1、生成秘钥
输入ssh-keygen,中间没有空格,输入命令之后,连续按3个回车。
[root@linux1 .ssh]# ssh-keygen
Generating public/private rsa key pair.
Enter file in which to save the key (/root/.ssh/id_rsa):
Enter passphrase (empty for no passphrase):
Enter same passphrase again:
Your identification has been saved in /root/.ssh/id_

SSH免密登录通过在~/.ssh目录下管理authorized_keys、id_rsa等文件实现。生成步骤包括使用ssh-keygen创建密钥对,然后将公钥发送到目标机器。如果遇到ssh-copy-id时不知密码,可手动复制公钥。问题可能在于公钥粘贴错误,需检查并重新粘贴。
最低0.47元/天 解锁文章
4547

被折叠的 条评论
为什么被折叠?



