sshd服务

it2022-05-05  218

文章目录

sshd服务1.sshd简介2.sshd的key认证2.1生成key认证2.2加密服务2.3分发钥匙2.4在客户端登陆服务器 3.sshd的安全设定4.添加sshd登陆信息5.用户登陆审计5.1 w5.2 last5.3 lastb

sshd服务

1.sshd简介

sshd = secure shell 可以通过网络在主机开启shell的服务 连接方式: ssh username@ip ##文本模式的链接 ssh -X username@ip ##链接成功后可以开启图形 注意: 第一次链接陌生主机要建立认证文件,所以会询问是否要输入‘yes’,再次链接时文件~/.ssh/know_hosts已存在 远程复制: scp (-r) 文件 用户名@ip: 文件路径 ##上传(把文件给别人) scp (-r) 用户名@ip:文件 文件路径 ##下载(从别人电脑拷文件)

2.sshd的key认证

2.1生成key认证

[root@westos_server Desktop]# ssh-keygen ##生成密匙的命令 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 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: c2:fe:db:c0:28:50:e0:3e:15:af:d4:c3:fd:84:23:f5 kiosk@foundation7.ilt.example.com The key's randomart image is: +--[ RSA 2048]----+ | . . . | | . . = o o | | . + * + E | | . + o o + | | + . o S . | | o . + | | . o o | | . . o | | o.. | +-----------------+

2.2加密服务

[root@westos_server Desktop]# ssh-copy-id -i /root/.ssh/id_rsa.pub root@172.25.254.207 ##加密sshd服务 The authenticity of host '172.25.254.207 (172.25.254.207)' can't 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 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.207's password: Number of key(s) added: 1 Now try logging into the machine, with: "ssh 'root@172.25.254.207'" and check to make sure that only the key(s) you wanted were added. [root@westos_server Desktop]# cd /root/.ssh/ [root@westos_server .ssh]# ls authorized_keys id_rsa id_rsa.pub known_hosts ^(这个文件出现代表加密完成)

2.3分发钥匙

[root@westos_server .ssh]# scp /root/.ssh/id_rsa root@172.25.254.107:/root/.ssh/ ##给客户端发送钥匙

2.4在客户端登陆服务器

发现可以免密登陆则成功

3.sshd的安全设定

cat /etc/ssh/sshd.config PasswordAuthentication yes ##是否允许用户通过登陆系统的密码作ssshd认证 PermitRootLogin yes ##是否允许root用户通过ssshd的服务认证 AllowUsers 用户名1 用户名2 ##设定用户白名单,白名单出现默认不在其中的用户不能使用sshd DenyUsers 用户名 ##设定黑名单,黑名单出现默认不在其中的用户可以使用sshd

4.添加sshd登陆信息

vim /etc/motd ##文件内容就算登陆后显示的信息

5.用户登陆审计

5.1 w

w ##查看正在使用当前系统的用户 -f ##查看使用来源 -i ##显示ip /var/run/utmp (数据文件)

5.2 last

last ##查看使用过并退出的用户信息 /var/log/wtmp (数据文件)

5.3 lastb

lastb ##试图登陆但未成功的用户 /var/log/btmp (数据文件)


最新回复(0)