sshd服务篇



sshd服务
1.sshd简介

sshd = secure shell daemon
可以通过网络在主机中开启一个远程主机的shell环境的服务

服务端软件:sshd

连接方式:
ssh USERNAME@IP ##文本模式连接全程主机
ssh -X USERNAME ##可以在连接成功后打开图形
这里写图片描述
注意:
第一次连接陌生主机是要建立认证文件,需要输入yes

远程复制:
scp FILENAME USERNAME@IP:dir ##上传(dir为绝对路径)
scp USERNAME@IP:dir dir ##下载(dir为绝对路径)
这里写图片描述
注意:远程复制目录时,需要加-r参数

2.sshd的key认证

[root@server ~]# ssh-keygen ##生成密钥的命令
Generating public/private rsa key pair.
Enter file in which to save the key (/root/.ssh/id_rsa): ##指定保存加密字符的文件(使用默认)
Created directory ‘/root/.ssh’.
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:
3f:dd:83:7f:c6:51:36:c3:8b:d1:45:44:20:8d:d5:35 root@server
The key’s randomart image is:
+–[ RSA 2048]—-+
| .+oE*|
| … +|
| o .|
| . =o|
| S o.=|
| . . + o |
| o o o..|
| …+|
| .o |
+—————–+
这里写图片描述
这里写图片描述

2.加密服务
[root@server .ssh]# ssh-copy-id -i /root/.ssh/id_rsa.pub root@172.25.254.113
The authenticity of host ‘172.25.254.113 (172.25.254.113)’ can’t be established.
ECDSA key fingerprint is 65:4d:ac:8a:c9:58:82:b5:0c:91:c4:ef:a5:e6:f6:65.
Are you sure you want to continue connecting (yes/no)? yes
/usr/bin/ssh-copy-id: INFO: attempting to log in with the new key(s), to filter out 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.113’s password:

Number of key(s) added: 1

Now try logging into the machine, with: “ssh ‘root@172.25.254.113’”
and check to make sure that only the key(s) you wanted were added.

[root@server .ssh]# ls
authorized_keys id_rsa id_rsa.pub known_hosts
^
此文件出现表示加密成功

3.分发密钥(发钥匙)
scp /root/.ssh/id_rsa root@172.25.254.213:/root/.ssh/

4.测试登陆
在客户端中(desktop)
[root@client ~]# ssh root@172.25.254.113
Last login: Fri Aug 10 00:52:50 2018 from foundation13.ilt.example.com
[root@server ~]#
连接时登陆发现不需要密码
这里写图片描述

3.sshd的安全设定

78 PasswordAuthentication yes|no ##是否允许用户通过登陆系统的密码做sshd的认证
48 PermitRootLogin yes ##是否允许root用户通过sshd服务登陆系统
Allowusers student westos ##设定用户白名单,白名单中出现的用户可以通过sshd登陆系统
Denyusers student westos ##设定用户黑名单,黑名单中出现的用户不能通过sshd登陆系统

这里写图片描述
这里写图片描述

4.添加sshd登陆信息

vim /etc/motd ##文件内容就是登陆后显示的信息
这里写图片描述

5.用户的登录审计

1.w ##查看正在使用当前系统的用户
w -f ##查看使用来源
w -i ##显示ip
这里写图片描述
2.last ##查看使用过并退出的用户信息
这里写图片描述
3.lastd ##查看试图登录但没有成功的用户

这里写图片描述

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值