#######################系统进程及服务的控制以及ssh的免密登陆################
1、什么是进程
进程就是系统没有完成并且正在进行的工作
程序--运行----进程(可以被cpu去调度)
进程--运行完毕---程序
2、进程的查看
ps -a 在当前环境中运行的进程(不包含详细信息)
a 在当前环境中运行的进程(包含详细信息)
-A 所有进程
-u 显示进程的用户信息
f 显示进程pid
e 显示进程调用环境工具的详细信息
x 所有进程
ps -a 和 ps a
ps常用组合
ps aux 显示系统中所有进程并显示进程用户
ps ef 显示进程的详细信息和pid
ps ax 显示当前系统中的所有进程
显示进程的指定信息
ps - o comm 显示进程的名称
user 进程的拥有者
group 进程的所属组
%cpu 进程对cpu的使用率
%mem 进程对内存的使用率
pid 进程的pid
nice 进程的优先级
进程对cpu和mem的使用率的排序
ps ax --sort=+%cpu 对进程的cpu的使用率进行正序的排列
ps ax --sort=-%cpu 对进程的cpu的时使用率进行逆序的排列
ps ax --sort=-%mem 进程对内存的使用率进行逆序的排列
ps ax --sort=+%mem 进程对内存的使用率进行正序的排列
[root@localhost Desktop]# ps -o comm,%cpu,pid,%mem,user,group,nice --sort=+%cpu
COMMAND %CPU PID %MEM USER GROUP NI
bash 0.0 2594 0.2 root root 0
ps 0.0 2911 0.1 root root 0
3、进程优先级
1、进程优先级范围
-20~19 (数字越小优先级越高)
2、查看进程的优先级级别
ps ax -o pid,nice,comm
3、改变进程的优先级
renice -n 5 30041 更改pid为30041进程的优先级为5
4、指定某个优先级开启进程
nice -n 6 vim filename & 开启vim并且指定程序优先级为6
4、环境中进程的前后台调用
jobs 查看被打入后台的进程
ctrl + z 把占用终端的进程打入后台
fg job的号数 把后台的进程调回前台(在前台运行,占用终端)
bg job的号数 把后台暂停的进程运行(在后台运行)
comm & 让命令直接在后台运行
5、什么是服务
linux中的服务是一类常驻内存中的进程
这类进程启动后就在后台当中一直持续不断的运行
用什么控制服务:系统的初始化进程可以对服务进行相应的控制
当前系统的初始化进程是什么:systemd 系统的初始化进程
服务的控制命令:
systemctl list-units 列出已经开启的服务当前的状态
list-unit-files 列出所有服务开机启动的状态
set-default multi-user.target 设定系统的启动级别为多用户模式(无图形)
set-default graphical.target 设定系统启动级别为图形模式
start 服务名称 开启服务
stop 服务名称 关闭服务
restart 服务名称 重启服务
reload 服务名称 重新加载服务
enable 服务名称 开机自启服务
disable 服务名称 开机不自启服务
6、sshd服务
(1)远程连接
ssh root@172.25.254.XX #远程连接172.25.254.XX,不开启图形界面
ssh root@172.25.254.XX -X #远程连接172.25.254.XX并开启图形界面
ssh 远程主机用户@远程主机ip -X 调用远程主机图形工具
ssh 远程主机用户@远程主机ip command 直接在远程主机运行某条指令
cheese 打开摄像机
ps aux | grep cheese
kill -9 pid号 杀死进程
(2)ssh的免密登陆
环境:desktop :172.25.254.119
server :172.25.254.219
实验目的:想要server200的root用户可以免密登陆desktop155的root用户
desktop155:
[root@desktop155 Desktop]# 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:
63:56:5d:96:f7:a6:12:63:04:e2:f9:e9:b9:90:0f:46 root@desktop155
The key's randomart image is:
+--[ RSA 2048]----+
| . .. o. |
| . o ..o. .|
| o ... ..|
| o .+ o|
| E o. o o |
| + + .. . |
| = o . |
| . + . |
| o |
+-----------------+
[root@desktop155 Desktop]# cd /root/.ssh/
[root@desktop155 .ssh]# ls
id_rsa id_rsa.pub
[root@desktop155 .ssh]# ssh-copy-id -i /root/.ssh/id_rsa.pub root@172.25.254.155 #####给自己的超级用户加锁
The authenticity of host '172.25.254.155 (172.25.254.155)' 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.155's password:
Number of key(s) added: 1
Now try logging into the machine, with: "ssh 'root@172.25.254.155'"
and check to make sure that only the key(s) you wanted were added.
[root@desktop155 .ssh]# scp /root/.ssh/id_rsa root@172.25.254.200:/root/.ssh/ 把私钥传给可以免密登陆自己的虚拟机
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
Warning: Permanently added '172.25.254.200' (ECDSA) to the list of known hosts.
root@172.25.254.200's password:
id_rsa 100% 1679 1.6KB/s 00:00
server200:
[root@server200 .ssh]# ssh root@172.25.254.155
The authenticity of host '172.25.254.155 (172.25.254.155)' 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.155' (ECDSA) to the list of known hosts.
Last login: Wed Jan 9 22:22:53 2019 from 172.25.254.55
[root@desktop155 ~]#
实验目的:想要server200的student用户可以免密登陆desktop155的root用户
desktop155:
[root@desktop155 .ssh]# scp /root/.ssh/id_rsa student@172.25.254.200:/home/student/.ssh/
student@172.25.254.200's password:
id_rsa 100% 1679 1.6KB/s 00:00
[root@desktop155 .ssh]#
server200:
[root@server200 .ssh]# su - student
[student@server200 ~]$ cd /home/student/.ssh/
[student@server200 .ssh]$ ls
authorized_keys id_rsa
[student@server200 .ssh]$ ssh root@172.25.254.155
The authenticity of host '172.25.254.155 (172.25.254.155)' 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.155' (ECDSA) to the list of known hosts.
Last login: Wed Jan 9 22:30:20 2019 from 172.25.254.200
[root@desktop155 ~]#