linux笔记整理(8、9)

来源:互联网 发布:微信开发教程 php 编辑:程序博客网 时间:2024/06/16 02:22

######系统服务的控制######

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就是这种模式

active(exited)                                 //执行一次就正常结束的服务,

                                                   //目前并没有任何程序在系统中执行

active(waiting)                                //正在执行当中

inactive                                         //服务关闭

enabled                                         //服务开机启动

disabled                                        //服务开启不自启

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

 

####openssh-server####

功能:让远程主机可以通过网络访问sshd服务,开始一个安全shell

#####客户端连接方式#####

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

[root@desktop0 ~]# ssh root@172.25.0.11

The authenticity of host ‘172.25.0.11 (172.25.0.11)’ can’t beestablished.

ECDSA key fingerprint iseb: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.0.11’ (ECDSA) to the list ofknown host

root@172.25.0.11’s password:          //远程用户密码

[root@server0 ~]#              //登陆成功

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

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

#####sshkey加密#####

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@server.example.com

The key’s randomart image is:

[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.0.11

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

-i                      //指定加密key文件

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

root      //加密用户为root

172.25.0.11  //被加密主机ip

 

3.   分发钥匙给client主机

[root@sercer0 ~]# scp /root/.ssh/id_rsa.pub         root@172.25.0.11

 

4.   测试

[root@desktop0 ~]# ssh root@172.25.0.11         //通过id_rsa直接连接不需要输入用户密码

Last login : Mon Oct  3 03:58:102016 from 172.25.0.250

[root@server0 ~]#

 

 

0 0
原创粉丝点击