Linux的ssh服务以及管理命令

       SSH 为 Secure Shell 的缩写,由 IETF 的网络小组(Network Working Group)所制定;SSH 为建立在应用层基础上的安全协议。SSH 是目前较可靠,专为远程登录会话和其他网络服务提供安全性的协议。利用 SSH 协议可以有效防止远程管理过程中的信息泄露问题。

一、ssh基本服务

1.sshd环境搭建
设置两个虚拟机IP地址172.25.254.100和172.25.254.200



2.连接方式:

    ssh    username@ip  ##文本模式的链接
    ssh -X username@ip  ##可以在链接成功后开机图形

  

  注意:
        第一次链接陌生主机是要建立认证文件
        所以会询问是否建立,需要树入yes
        在次链接此台主机时,因为已经生成~/.ssh/know_hosts文件所以不需要再次输入yes


3.远程复制:

    scp file root@ip:dir        ##上传
    scp root@ip:file dir        ##下载

二、sshd 的key认证

1.生成认证KEY

[root@server ~]# 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:
86:61:e4:f1:6e:51:3a:4b:d7:3c:1b:2f:e8:3f:b0:5d root@server.example.com
The key's randomart image is:
+--[ RSA 2048]----+
|      o   .      |
|     o o o o     |
|      + * . =    |
|     . = = . =   |
|      . S . o .  |
|       o ..  .E  |
|          .+ .   |
|          ..o    |
|            ..   |
+-----------------+


2.加密服务

[root@server .ssh]# ssh-copy-id -i /root/.ssh/id_rsa.pub root@172.25.254.200  ##加密sshd服务
The authenticity of host '172.25.254.200 (172.25.254.200)' 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.269's password:

Number of key(s) added: 1

Now try logging into the machine, with:   "ssh 'root@172.25.254.200"
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.100:/root/.ssh/

4.测试
在客户主机中(172.25.254.100)
ssh root@172.25.254.200     ##连接时发现直接登陆不需要root登陆系统的密码认证


三、.sshd的安全设定

vim /etc/ssh/sshd_config          ##root权限下配置
78 PasswordAuthentication yes|no  ##是否允许用户通过登陆系统的密码做sshd的认证
48 PermitRootLogin yes|no         ##是否允许root用户通过sshd服务的认证
52 Allowusers student westos      ##设定用户白名单,白名单出现默认不再名单中的用户不能使用sshd
53 Denyusers    westos            ##设定用户黑名单,黑名单出现默认不再名单中的用户可以使用sshd
                                  ##本次实验我将Allowusers 和Denyusers 放在 79 80 中

 

四、.添加sshd登陆登陆信息

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

五、用户的登陆审计

w        ##查看正在使用当前系统的用户
    -f   ##查看使用来源
    -i   ##显示IP

  last  

 

  last     /var/run/utmp   ##查看使用过并退出的用户信息
           /var/log/wtmp   ##试图登陆但没成功的用户
           /var/log/btmp

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值