学习运维——系统服务控制、openssh

来源:互联网 发布:淘宝涛哥电玩店黑不黑 编辑:程序博客网 时间:2024/05/22 06:24

第八单元:系统服务的控制

 

服务器:为网络中其他计算机提供某些服务的安装了某类软件的计算机系统

 

1.systemd

系统初始化程序,系统开始的第一个进程,pid为1

 

2.systemctl 命令

systemctl list-units ##列出当前系统服务的状态

systemctl list-unit-files ##列出服务的开机状态

systemctl status sshd ##查看指定服务的状态

systemctl stop sshd ##关闭指定服务

systemctl start sshd ##开启指定服务

systemctl restart sshd ##从新启动服务

systemctl enable sshd ##设定指定服务开机开启

systemctl disable sshd ##设定指定服务开机关闭

systemctl reload sshd ##使指定服务从新加载配置

systemctl list-dependencies sshd ##查看指定服务的倚赖关系

systemctl mask sshd ##冻结指定服务

systemctl unmask sshd ##启用服务

systemctl set-default multi-user.target ##开机不开启图形

systemctl set-default graphical.target ##开机启动图形

 

3.服务状态

systemctl status 服务名称

 

loaded ##系统服务已经初始化完成,加载过配置

active(running) ##正有一个或多个程序正在系统中执行,

# vsftpd 就是這種模式

 

atcive(exited) ##僅執行一次就正常結束的服務,

# 目前並沒有任何程序在系統中執行

 

atcive(waiting) ##正在執行當中,

# 不過還再等待其他的事件才能繼續處理

 

inactive ##服务关闭

enbaled ##服务开机启动

disabled ##服务开机不自启

static ##服务开机启动项不可被管理

failed ##系统配置错误

 


第九单元:openssh-server

 

1.怎么连接远程主机

ssh 远程主机用户@远程主机ip

示例:

[kiosk@foundation90 Desktop]$ ssh root@172.25.254.10

The authenticity of host '172.25.254.10 (172.25.254.10)' 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

Warning: Permanently added '172.25.254.10' (ECDSA) to the list of known hosts.

root@172.25.254.10's password:

Last login: Fri Jan 13 07:45:29 2017

 

ssh 远程主机用户@远程主机ip -X ##调用远程主机图形工具


ssh     远程主机用户@远程主机ip command ##直接在远程主机运行某条命令

 

2.禁止别人连接我电脑上的超级用户

修改配置文件/etc/ssh/sshd_config


客户端

[root@foundation90 ~]# ssh root@172.25.254.10

root@172.25.254.10's password:

Permission denied, please try again.

root@172.25.254.10's password:

 

3.sshkey加密

我想让我的房子(主机)更安全,我需要手里有锁和钥匙,怎么才能有呢?用ssh-keygen 生成,那有了锁我就要把我的房子(电脑)锁上,ssh-copy-id -i /root/.ssh/id_rsa.pub  root@172.25.254.10,那锁上之后我要是想让某个人可以进我的房子,我需要给他发一把钥匙id_rsa 。

 

1)生成公钥私钥

[root@server0 ~]# ssh-keygen ##生成公钥私钥工具

Generating public/private rsa key pair.

Enter file in which to save the key (/root/.ssh/id_rsa):[enter] ##加密字符保存文件(建议用默认)

Created directory '/root/.ssh'.

Enter passphrase (empty for no passphrase): [enter] ##密钥密码,必须>4个字符

Enter same passphrase again: [enter] ##确认密码

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:

ab:3c:73:2e:c8:0b:75:c8:39:3a:46:a2:22:34:84:81 root@server0.example.com

The key's randomart image is:

+--[ RSA 2048]----+

|o                |

|E.               |

|..               |

|.  . o           |

|.o. * . S        |

|oo.o o   .       |

|+ =. .  .        |

|o. oo.+..        |

|    ..o*.        |

+-----------------+

[root@server0 ~]# ls /root/.ssh/

id_rsa  id_rsa.pub

id_rsa ##私钥,就是钥匙

id_rsa.pub ##公钥,就是锁

 


2)添加key认证方式

[root@server0 ~]# ssh-copy-id -i /root/.ssh/id_rsa.pub  root@172.25.254.10

ssh-copy-id ##添加key认证方式的工具

-i ##指定加密key文件

/root/.ssh/id_rsa.pub ##加密key

root ##加密用户为root

172.25.0.11 ##被加密主机ip


3)分发钥匙给client主机

[root@server0 ~]# scp /root/.ssh/id_rsa root@172.25.254.90:/root/.ssh/


4)测试

 

[root@foundation90 ~]# ssh root@172.25.254.10  用钥匙打开不用输入密码

Last failed login: Fri Jan 13 09:42:15 EST 2017 from 172.25.254.10 on ssh:notty

There was 1 failed login attempt since the last successful login.

Last login: Fri Jan 13 09:26:54 2017 from 172.25.254.90

[root@localhost ~]#

 

 

4.提升openssh的安全级别

1.openssh-server配置文件

/etc/ssh/sshd_config

78 PasswordAuthentication yes|no ##是否开启用户密码认证,yes为支持no为关闭

48 PermitRootLogin yes|no ##是否允许超级用户登陆

49 AllowUsers student westos ##用户白名单,只有在名单中出现的用户可以使用sshd建立shell

50 DenyUsers westos ##用户黑名单


0 0
原创粉丝点击