ssh免密登陆

ssh免密登陆

ssh密匙认证过程

# rsa(默认)和 dsa 是服务器链接的时候,必需要使用的协议

没有远程登陆(ssh协议链接)过的用户**家目录**下没有.ssh目录
远程xhell链接过家目录下才有.ssh目录

vim粘贴以前要进入编辑模式

虚拟机外网网卡链接,xshell才能链接
杀掉sshd进程或者关闭sshd进程 可致使xshell连不上,须要重启虚拟机才能链接(去机房?)

web01服务器是能够ping外网IP和内网IP的
若是web01服务器断开内网网卡,内网虚拟机断开外网网卡的链接
那么web01 就不能ping内网IP了,由于内网和外网是不能直接链接的,除非web01打开内网网卡,而且和内网虚拟机处于同一个lan区段,内网虚拟机才能间接的链接外网

系统全部用户均可以使用免密匙的方式进行远程链接

[root@web01 ~]# ssh-keygen			#默认使用rsa协议生成密匙
[root@web01 ~]# ssh-keygen -t dsa	 # -t 指定使用dsa 协议生成密匙 

1.#建立密钥对
[root@web01 ~]# 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_rsa.
Your public key has been saved in /root/.ssh/id_rsa.pub.
The key fingerprint is:
SHA256:RbzrPnQlDvH5EclGBCiTNc6IyYAVh4P97wIaVzNMUU4 root@web01
The key's randomart image is:
+---[RSA 2048]----+		#建立密匙使用的协议
|   =+oooE++..=o. |
|  o ++.=+=+.  =  |
|     =+ oo++ o . |
|      *  .o + o  |
|     . +S  + + . |
|  . o   . o o .  |
|   + . . o .     |
|  .   . . o      |
|       . ...     |
+----[SHA256]-----+		#加密算法
[root@web01 ~]# cd .ssh/
[root@web01 ~/.ssh]# ll
total 12
-rw------- 1 root root 1675 May 11 19:15 id_rsa		#私钥,至关于钥匙
-rw-r--r-- 1 root root  392 May 11 19:15 id_rsa.pub	 #公钥,至关于锁
-rw-r--r-- 1 root root  170 May 10 10:09 known_hosts

2.#发送公钥(须要输入yes和密码,由于使用了ssh远程链接协议),能够发到root用户,也能够发到普通用户
#查看ssh-copy-id 命令 属于哪一个包
[root@web01 ~]# yum provides ssh-copy-id
openssh-clients-7.4p1-21.el7.x86_64
[root@web02 ~]# rpm -q openssh-clients	#linux系统默认安装过了
openssh-clients-7.4p1-21.el7.x86_64

-i:指定公钥文件

把本地的ssh公钥文件 安装 到远程主机对应的家目录下,而且受权为600且更名(#不是单纯的拷贝)
默认拷贝到 指定主机,指定用户的家目录下
[root@web01 ~/.ssh]# ssh-copy-id -i /root/.ssh/id_rsa.pub root@172.16.1.41

#链接
[root@web01 ~/.ssh]# ssh 'root@172.16.1.41'		#不须要输入密码,会有默认输出

#10.0.0.7查看公钥内容
[root@web01 ~/.ssh]# cat id_rsa.pub

#10.0.0.41,查看公钥内容,能够发现公钥内容是同样的
[root@backup ~]# cd .ssh/
[root@backup ~/.ssh]# ll
total 8
-rw------- 1 root root 392 May 11 19:21 authorized_keys		# 600权限
-rw-r--r-- 1 root root 171 May  8 22:26 known_hosts
[root@backup ~/.ssh]# cat authorized_keys

2.#本身作公钥(不须要知道root密码)(当心串行让人头疼)
	1.查看生成的公钥并复制
	[root@web01 ~]# cat /root/.ssh/id_rsa.pub
	
	2.
	#建立.ssh目录,没用使用过ssh的用户 家目录下没有.ssh目录
	[root@web02 ~]# mkdir /root/.ssh/ 
    #粘贴公匙
	[root@web02 ~]# vim /root/.ssh/authorized_keys
	#文件受权,仿造文件权限
	chmod 600 /root/.ssh/authorized_keys
	#目录受权,仿造目录权限
	chmod 700 /root/.ssh
	
	3.链接
	[root@web01 ~]# ssh 10.0.0.8
相关文章
相关标签/搜索