1. 程式人生 > >Linux作業系統入門(4)

Linux作業系統入門(4)

程序的動態監控

1.top
1 顯示cpu每個核的負載
s 調整書信頻率
c cpu負載排序
m 記憶體使用量排序
h 檢視幫助
u 檢視指定使用者程序
k 對指定程序發起訊號
q 退出

控制服務

1.什麼是服務

2.用什麼控制服務
系統初始化程序可以對服務進行相應的控制

3.當前系統初始化程序是什麼
systemd 系統初始化程序
pstree 顯示系統中的程序樹

4.程序控制命令
ssh—>sshd
client server

systemctl	        服務控制命令
systemctl status  sshd	檢視服務狀態,inactive(不可用),active(可用)
systemctl start   sshd	開啟服務
systemctl stop	  sshd	關閉服務
systemctl restart sshd	重啟服務
systemctl reload  sshd	重新載入服務配置
systemctl enable  sshd 	設定服務開機啟動	
systemctl disable sshd 	設定服務開機不啟動
systemctl list-units	列出已經開啟服務的當前狀態
systemctl list-dependencies	列出服務依賴
systemctl set-default multi-user.target 	設定系統啟動級別為多使用者模式(無圖形)
systemctl set-default graphical.target   	設定系統啟動級別為圖形模式

sshd服務

1.sshd簡介
sshd = secure shell
可以通過網路在主機中開啟shell服務

客戶端軟體
ssh

連線方式:
ssh [email protected] 文字模式的連線
ssh -X [email protected] 可以在連線成功後開啟圖形

注意:
第一次連線陌生主機時需要建立認證檔案
會詢問是否建立,需要輸入yes
再次連線此主機時。因為已經生成~/.ssh/know_hosts

遠端複製:

scp	file	[email protected]:dir 	上傳(dir為絕對路徑)
scp	[email protected]
:file dir 下載(file為絕對路徑) scp -rp test [email protected]:dir 上傳目錄(dir為絕對路徑) scp -rp [email protected]:test dir 下載目錄(test為絕對路徑)

ssh的key認證

ssh-keygen	生成金鑰的命令
[[email protected] ~]# 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:
 12:ee:e7:0b:db:bd:50:47:e9:64:08:67:99:0a:ea:86 
[email protected]
The key's randomart image is: +--[ RSA 2048]----+ | . oo | | . +o. . | | ... .. = | | .. .. = | | o o S . o | | E o. . . . | | . o o | | * o | | . +.o. | +-----------------+

當出現上面的情況時說明金鑰已經生成

[[email protected] .ssh]# ssh-copy-id -i /root/.ssh/id_rsa.pub [email protected]
 The authenticity of host '172.25.254.209 (172.25.254.209)' can't be established.
 ECDSA key fingerprint is 65:4d:ac:8a:c9:58:82:b5:0c:91:c4:ef:a5:e6:f6:65.
 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
 [email protected]'s password: 

 Number of key(s) added: 1

 Now try logging into the machine, with:   "ssh '[email protected]'"
 and check to make sure that only the key(s) you wanted were added.

 [[email protected] .ssh]# ls 
 authorized_keys  id_rsa  id_rsa.pub  known_hosts
 當出現第一個檔案時說明加密成功

分發鑰匙

 **scp /root/.ssh/id_rsa [email protected]:/root/.ssh/**

測試
在客戶主機中(172.25.254.209)

ssh [email protected]
連線時發現直接登入不需要密碼

ssd的安全設定

 PasswordAuthentication yes		是否允許使用者通過密碼做sshd認證
 PermitRootLogin yes			是否允許root使用者通過sshd服務的認證
 AllowUsers student westos		設定使用者白名單,白名單出現,預設不在白名單的使用者不能使用sshd
 DenyUsers westos			設定使用者黑名單,黑名單出現,預設不在黑名單的使用者可以使用sshd

新增sshd登入資訊

 vim /etc/motd				檔案內容就是登陸後的資訊顯示

使用者登入審計

1.w 檢視正在正在使用當前系統的使用者
-f 檢視使用來源
-i 顯示IP
在這裡插入圖片描述
2last 檢視使用過並退出的使用者資訊
在這裡插入圖片描述

3.lastb 試圖登入但沒成功的使用者
在這裡插入圖片描述

檔案在系統中傳輸

scp:

scp	file	[email protected]:dir 	上傳(dir為絕對路徑)
scp	[email protected]:file dir	下載(file為絕對路徑)

scp -rp test	[email protected]:dir	上傳目錄(dir為絕對路徑)
scp -rp [email protected]:test	dir	下載目錄(test為絕對路徑)

rsync
遠端同步,速度快,預設會忽略檔案屬性,連結檔案,裝置檔案
-r 同步目錄
-p 同步許可權
-o 同步檔案所有人
-g 同步檔案所有組
-t 同步時間
-l 同步連結檔案
-D 同步裝置檔案
tar
-c 建立
-x 解檔
-v 顯示過程
-f 指定歸檔檔名稱
-t 檢視歸檔檔案內容
-r 新增檔案到歸檔中
–get 解檔指定檔案
–delete 刪除歸檔中的指定檔案
-C 指定解檔目錄

壓縮

zip
zip -r  xxx.tar.zip	xxx.tar
unzip	xxx.tar.zip

gz
gzip	xxx.tar
gunzip	xxx.tar.gz
===
tar zcf xxx.tar.gz
tar zxf	xxx.tar.gz

bz2
bzip2	xxx.tar
bunzip2	xxx.tar.bz2
===
tar jcf xxx.tar.bz2 /xxx
tar jxf xxx.tar.bz2

xz	
xz	xxx.tar
unxz	xxx.tar.xz
===
tar Jcf xxx.tar.xz /xxx
tar Jxf xxx.tar.xz	

查看了壓縮檔案的大小並解壓
在這裡插入圖片描述