09 使用ssh服务管理远程主机
创建网络会话
nmcli connection show
[root@linuxprobe ~]# nmcli connection add con-name company ifname eno16777736 autoconnect no type ethernet ip4 192.168.10.10/24 gw4 192.168.10.1
[root@linuxprobe ~]# nmcli connection add con-name house type ethernet ifname eno16777736
[root@linuxprobe ~]# nmcli connection show
[root@linuxprobe ~]# nmcli connection up house
[root@linuxprobe ~]# vim /etc/sysconfig/network-scripts/ifcfg-eno16777736
TYPE=Ethernet
BOOTPROTO=none
ONBOOT=yes
USERCTL=no
DEVICE=eno16777736
MASTER=bond0
SLAVE=yes
[root@linuxprobe ~]# vim /etc/sysconfig/network-scripts/ifcfg-eno33554968
TYPE=Ethernet
BOOTPROTO=none
ONBOOT=yes
USERCTL=no
DEVICE=eno33554968
MASTER=bond0
SLAVE=yes
[root@linuxprobe ~]# vim /etc/sysconfig/network-scripts/ifcfg-bond0
TYPE=Ethernet
BOOTPROTO=none
ONBOOT=yes
USERCTL=no
DEVICE=bond0
IPADDR=192.168.10.10
PREFIX=24
DNS=192.168.10.1
NM_CONTROLLED=no
[root@linuxprobe ~]# vim /etc/modprobe.d/bond.conf
alias bond0 bonding
options bond0 miimon=100 mode=6
[root@linuxprobe ~]# systemctl restart network
远程控制服务
配置sshd服务
主配置文件 /etc/服务名称/服务名称.conf 保存了最重要的参数
普通配置文件
[root@linuxprobe ~]# vim /etc/ssh/sshd_config
[root@linuxprobe ~]# systemctl restart sshd
[root@linuxprobe ~]# systemctl enable sshd
[root@linuxprobe ~]# ssh 192.168.10.10
安全密钥验证
[root@linuxprobe ~]# ssh-keygen
[root@linuxprobe ~]# ssh-copy-id 192.168.10.10
远程传输命令scp
[root@linuxprobe ~]# scp /root/readme.txt 192.168.10.20:/home
[root@linuxprobe ~]# scp 192.168.10.20:/etc/redhat-release /root
[root@linuxprobe ~]# cat redhat-release
不间断会话服务
[root@linuxprobe ~]# mkdir -p /media/cdrom
[root@linuxprobe ~]# mount /dev/cdrom /media/cdrom
mount: /dev/sr0 is write-protected, mounting read-only
[root@linuxprobe ~]# vim /etc/yum.repos.d/rhel7.repo
[rhel7]
name=rhel7
baseurl=file:///media/cdrom
enabled=1
gpgcheck=0
[root@linuxprobe ~]# yum install screen
管理远程会话
[root@linuxprobe ~]# screen -S backup
[root@linuxprobe ~]# screen -ls
[root@linuxprobe ~]# screen vim memo.txt
[root@linuxprobe ~]# screen -S linux
[root@linuxprobe ~]# tail -f /var/log/messages
[root@linuxprobe ~]# screen -ls
[root@linuxprobe ~]# screen -r linux
[root@linuxprobe ~]# tail -f /var/log/messages
会话共享功能
[root@client A ~]# ssh 192.168.10.10
The authenticity of host '192.168.10.10 (192.168.10.10)' can't be established.
ECDSA key fingerprint is 70:3b:5d:37:96:7b:2e:a5:28:0d:7e:dc:47:6a:fe:5c.
Are you sure you want to continue connecting (yes/no)? yes
Warning: Permanently added '192.168.10.10' (ECDSA) to the list of known hosts.
root@192.168.10.10's password:此处输入root管理员密码
Last login: Wed May 4 07:56:29 2017
[root@client A ~]# screen -S linuxprobe
[root@client A ~]#
然后,使用ssh服务程序将终端B远程连接到服务器,并执行获取远程会话的命令。接下来,两台主机就能看到相同的内容了。
[root@client B ~]# ssh 192.168.10.10
The authenticity of host '192.168.10.10 (192.168.10.10)' can't be established.
ECDSA key fingerprint is 70:3b:5d:37:96:7b:2e:a5:28:0d:7e:dc:47:6a:fe:5c.
Are you sure you want to continue connecting (yes/no)? yes
Warning: Permanently added '192.168.10.10' (ECDSA) to the list of known hosts.
root@192.168.10.10's password:此处输入root管理员密码
Last login: Wed Feb 22 04:55:38 2017 from 192.168.10.10
[root@client B ~]# screen -x
[root@client B ~]