通常,.ssh目录中具有如下四个文件:
1 2 3 4 5 6 7 8 |
root@hadoop002:~/.ssh# pwd /root/.ssh root@hadoop002:~/.ssh# ls -l total 16 -rw------- 1 root root 392 Dec 2 11:50 authorized_keys -rw------- 1 root root 1675 Dec 2 13:47 id_rsa -rw-r--r-- 1 root root 396 Dec 2 13:47 id_rsa.pub -rw-r--r-- 1 root root 444 Dec 2 13:49 known_hosts |
其中:
1、id_rsa和id_rsa.pub通常由 ssh-keygen -t rsa生成,分别是私钥和公钥:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 |
root@hadoop002:~# ssh-keygen -t rsa 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_rsa. Your public key has been saved in /root/.ssh/id_rsa.pub. The key fingerprint is: SHA256:K7D5aT6oQOTDJBcSRC/BAQhWH/ATXyDlw0m13JLatO0 root@hadoop002 The key's randomart image is: +---[RSA 2048]----+ |%B+o.+.+oo | |ooo.o O + + | |.+.. + * * . | |*.. . = + | | = . .So . | |. . + .. | |. o.. . E | | . ..oo | | .. o+. | +----[SHA256]-----+ |
2、known_hosts中保存了曾经通过ssh连接过主机的公钥,即:A通过ssh首次连接到B时,B会将公钥1(host key)传递给A,A将公钥1存入known_hosts文件中,以后A再连接B时,B依然会传递给A一个公钥2,ssh会对比公钥1与公钥2 是否相同来进行简单的验证,如果公钥不同则会发出 Host key verification failed的警告, 避免受到DNS Hijack之类的攻击。
3、authorized_keys能够实现两台主机之间的免密登陆,即:将A的公钥id_rsa.pub添加到B的authorized_keys中之后,A即可免密访问B了,具体方法有两种,可参见http://www.meilongkui.com/archives/1378
转载时请保留出处,违法转载追究到底:进城务工人员小梅 » .ssh目录中相关文件的理解