Linux機器相互登錄
阿新 • • 發佈:2018-01-30
51cto 退出 1.5 for color ssh tin div enforce 克隆虛擬機
關閉虛擬機
#shutdown -h now
虛擬機創建完成,開啟克隆的虛擬機,修改ip地址
#vi /etc/sysconfig/network-scripts/ifcfg-ens33
#systemctl restart network.service #ifconfig ens33 #hostnamectl set-hostname apenglinux-002 #exit
退出重新登陸,發現主機名已經改為apenglinux-002,主機名已經寫入到了配置文件/etc/hostname當中了
用Xshell連接apenglinux-001,apenglinx-002,在apenglinux-001上登陸到apenglinux-002上
[root@apenglinux-001 ~]# ssh -p 22 [email protected] [root@apenglinux-002 ~]# ssh -p 22 [email protected]
這樣就實現了Linux機器相互登錄了
在apenglinux-001上用私鑰連接apenglinux-002
在apenglinux-001生成密鑰對
[root@apenglinux-001 ~]# 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:cT+xqNoVvKkiE/hwWKgKXdzFoM/isiil+oHWaDivJ2Q root@apenglinux-001 The key's randomart image is: +---[RSA 2048]----+ | .o | | . o | | o.. .. . . | | . +o. + o o | | o =. o S + + | |+EO.o. . + . | |O*o=.. . + | |B+.++ .o o | |*=+ o..o | +----[SHA256]-----+
將公鑰存入到apenglinux-002:~/.ssh/authorized_keys文件中
[root@apenglinux-002 ~]# vi .ssh/authorized_keys
[root@apenglinux-002 ~]# setenforce 0
在 apenglinux-001中登陸到apenglinux-002中
[root@apenglinux-001 ~]# ssh -p 22 [email protected] Enter passphrase for key '/root/.ssh/id_rsa': Last login: Tue Jan 30 10:59:00 2018 from 192.168.221.10 [root@apenglinux-002 ~]#
登陸成功
Linux機器相互登錄