#####sshd服务#####
1.查询ip地址:ip addr show eth0
2.更改名称:hostnamectl set-hostname (ssh-server).westos.com
ssh-server: 更改的用户名
更改用户名时会自动生成/root/.ssh/ 文件,为确保系统文件的原始性建议改完用户名删除该文件([root@ssh-server Desktop]# rm -fr /root/.ssh/)
##.控制服务###
1.什么是服务(sshd)
2.用什么控制服务
系统初始化进程可以对服务进行相应控制(主机与虚拟机网络连接,对虚拟机远程操控)
操作方法:
inet 172.25.6.250/24 brd 172.25.6.255 scope global br0
(172.25.6.250/24)当前真机ip
2.虚拟机打开shell设ip地址
输入命令:nm-connection-editor
delete(Ethernet connection 1)--->Add(Ethernet Create)--->Device MAC address(选中唯一项etno)--->IPv4 Settings Method(Manual)--->add(Address [172.25.6.111(1-254之间任意数),Netmask(24),Gateway(只点击一下))--->save--->Close
3.打开虚拟机shell输入ip addr show eth0 会出现虚拟机ip地址
真机shell上ping 172.25.6.111(PING 172.25.6.111 (172.25.6.111) 56(84) bytes of data.
64 bytes from 172.25.6.111: icmp_seq=1 ttl=64 time=0.223 ms
)连接成功
4.通过真机此时可以控制虚拟机(在真机上创建文件,虚拟机上会出现该文件)
3.当前系统初始化进程时什么
systemd ##系统初始化进程
pstree ##显示系统中的进程树
4.进程控制命令
ssh(客户端) ----->sshd(服务端)
client server
`##sshd打开对本身没有意义,但方便客户端连接,sshd关闭后客户端无法连接服务端
systemctl ##服务控制命令
systemctl status sshd ##查看服务状态,inactive(不可用), active(可用)
systemctl start sshd ##开启服务
systemctl stop sshd ##关闭服务
systemctl restart sshd ##重启服务
systemctl reload sshd ##重新加载服务设备
systemctl disable sshd ##设定服务开机不启动(不开启sshd)
systemctl list-units ##列出已经开启服务当前状态
systemctl list-unit-files ##列出所有服务开机启动状态,disable, enable,static(固定的不可控制的)
systemctl list-dependencies ##列出服务的依赖
systemctl set-default multi-user.target ##设定系统启动级别为多用户模式(无图形)
systemctl set-default graphical.target ##设定系统启动级别为图形模式 (设定系统启动时不会影响当前图形的状态)
##1.sshd简介##
sshd= secure shell 可以通过网络在主机中开机shell的服务(实现客户端对服务端的连接控制)
客户端软件
sshd
连接方式:
ssh username@ip ##文本模式链接
ssh -X username@ip ##可以在链接成功后打开主机图形
注意:
第一次链接陌生主机需要建立认证文件,询问是否建立 需要输入yes.
再次链接此台主机时,因为已生成~/.ssh/know-hosts文件,所以不需要再次输入yes
远程复制:(上传文件时输入-r)
scp file root@ip:dir #上传
scp root@ip:file dir #下载
操作方法:
[kiosk@foundations ~]$ ssh root@172.25.254.7(被链接人的主机ip)
root@172.25.254.7's password: (输入被链接人的主机密码)
[root@foundation7 ~]# scp -r kiosk@172.25.254.6:/home/kiosk/Desktop/* . (将kiosk@172.25.254.6:/home/kiosk/Desktop/的所有传到 当前位置【[root@foundation7 ~]】)
[root@foundation7 ~]# scp -r kiosk@172.25.254.7:/home/kiosk/Desktop/* .(将kiosk@172.25.254.7:/home/kiosk/Desktop/* 上所有传输到当前位置【我的主机桌面】)
##2.sshd的key认证
1.生成认证Key
Generating public/private rsa key pair.
Enter file in which to save the key (/home/kiosk/.ssh/id_rsa): ##指定保存加密字符的文件(使用默认)
Enter passphrase (empty for no passphrase): ##设定密码(Enter使用空密码)
Enter same passphrase again: ##确认密码
Your identification has been saved in /home/kiosk/.ssh/id_rsa. ##私钥(钥匙)
Your public key has been saved in /home/kiosk/.ssh/id_rsa.pub.##公钥(锁)
The key fingerprint is:
fe:1a:01:ba:f7:fe:1c:6e:c9:b5:b6:9c:7a:db:89:ee kiosk@foundations.westos.com
The key's randomart image is:
+--[ RSA 2048]----+
| |
| |
| . |
| . . |
| . S |
| . . . . |
| . . o..o . |
| . . =+o++ . |
| .++**Eoo |
+-----------------+
2.加密服务
ssh-copy-id -i /root/.ssh/id_rsa.pub root@172.25.254.106 ##加密sshd服务
The authenticity of host172.25.254.106(172.25.254.106)
cant be established. ECDSA key fingerprint is eb:24:0e:07:96:26:b1:04:c2:37:0c:78:2d:bc:b0:08 Are you sure you want to continue connecting(yes/no)? yes /usr/bin/ssh-copy-id: INFO:attempting to log in with the key(s),to filter out any that any that are already installed /usr/bin/ssh-copy-id: INFO: 1 key(s) remain to be installed --if you are prompted now it is to install the new keys root@172.25.254.106
s passwd:
Number of key(s) added:1
Now try logging into the machine,with:
"sshroot@172.25.254.106
"and check to make sure that only the key(s) you wanted wanted were added.
[root@localhost Desktop]#ls
authorized_keys id_rsa id_rsa.pub known_hosts
^
此文件出现表示加密完成
3.分发钥匙
scp /root/.ssh/id_rsa root@172.25.254.206:/root/.ssh/
4.测试
在客户主机中(172.25.254.206)
ssh root@172.25.254.106 ##连接时发现直接登陆不需要root登陆系统的密码认证
###3.sshd的安全设定###
78 PasswordAuthentication yes|no ##是否允许用户通过登录系统的密码作sshd的认证
48 PermitRootLogin yes|no ##是否允许root用户通过sshd的服务认证
52 Allowusers student westos ##设定用户白名单,白名单出现默认不在名单中的用户不能使用sshd
53 Denyusers westos ##设定用户黑名单,黑名单出现默认不在名单的用户可以使用sshd
注意:
1“##”表注释,系统不认可,要认可就要删除##
2.每添加一个指令,要恢复之前修改的指令;
3.做完实验要恢复所有指令:
###4.添加sshd登陆信息###
vim /etc/motd ##文件内容就是登陆后显示的信息
###5.用户的登陆审计###
1.w ##查看正在使用当前系统的用户
-f ##查看使用来源
-i ##显示ip
/var/run/utmp
2.last ##查看使用过并退出的用户信息
/var/log/wtmp
3.lastb ##查看试图登陆但没成功的用户信息
/var/log/btmp