Linuxの紹介
Linuxの開発履歴
Linuxシステムは1991年に誕生し、フィンランドの大学Linus Torvaldsと、後に参加した多くの愛好家によって共同開発されました。これはUNIXのブランチです。
Linuxはオープンソースソフトウェア、UNIXソースコード開発です
Linuxロゴ
Linuxカーネルバージョン
Linuxカーネルの公式ウェブサイト:www.kernel.org
カーネルバージョンの説明
2.6.8(2メジャーバージョン6マイナーバージョン8最後のバージョン)
カーネルバージョンと開発バージョンの違い
カーネルバージョン(数十M)が基盤であり、開発バージョンはカーネルに基づいて独自のデスクトップおよびアプリケーションプログラムを追加します。つまり、すべての企業が開発バージョンを開発できますが、それらはすべて同じカーネルを使用します。 。
主要なLinuxディストリビューション
主な違いはソフトウェアのインストールですが、他は基本的に同じです
オープンソースソフトウェア
オープンソースソフトウェアの機能、ほとんどのオープンソースソフトウェアは無料で、ソフトウェアのソースコード(安全)を入手でき、自由に広め、改善し、さらには販売することもできます
インターネットをサポートするオープンソーステクノロジー
ランプ
Linuxオペレーティングシステム
ApacheWebサーバー
MySQLデータベース
PHPプログラミング言語
Linuxアプリケーション
Linuxベースのエンタープライズサーバー
www.netcraft.com(このWebサイトを通じて、主要なWebサーバーで使用されているシステム、スニッフィング、ステップオンポイントについて問い合わせることができます)
組み込みアプリケーション(携帯電話、タブレット)
映画エンターテインメント業界A
ユーザーとグループ
Linuxオペレーティングシステムでのユーザー分類
通常のユーザーは管理者よりも権限が低く、システムにログインすることもできます
ルートスーパー管理者
ユーザーの分類とグループ
/ etc / passwdは、オペレーティングシステム内のすべてのユーザーの情報を保存します
root : x : 0 : 0 : root : /root : /bin/bash
HSP : x : 500 : 500 : : /home/HSP : /bin/bash
字段1:用户名称
字段2:密码占位符
字段3:用户的uid (0表示超级用户,500-60000表示普通用户,1-499表示程序用户)程序用户不允许登录系统
字段4:基本组的gid(先有组才有用户,先建立组再建立用户)
字段5:用户信息记录字段(这个字段基本上废弃了)
字段6:用户的家目录
字段7:用户登录系统后使用的命令解释器
/ etc / shadowはユーザーのパスワード情報を保存します
root:$6$Lx3szebY4fAW2wFq$nI19XWtQZosCU0yoCyD05Qw7AHSwfJi0uh27mrwVhmtWo1IcspLDIHaSDp1FLqxuwCvV27mE6wZqyha2q4JeC1:18673:0:99999:7:::
HSP:$6$N8BBW6c7uOPtmjZI$7o0ycutUSP/n7XgAPZ8WFdDrV8yRmTu6htR.qbk20z5AXWPXKq20XXCR4uGJPmkVkIzJNSyt0vXSYgnDVl0S31:18673:0:99999:7:::
字段1:用户名
字段2:用户密码加密后的字符串(sha加密)
字段3:距离1970年1月1日密码最近一次的修改时间(UNIX诞生时间)
字段4:密码的最短有效期(如果写3表示用户三天内不可以修改密码,0就是不限制)
字段5:密码的最长有效期(200多年,不建议这么长,建议设置为90天)
字段6:密码过期前7天警告
字段7:密码的不活跃期
字段8:用户的失效时间
/ etc / groupシステム内のすべてのグループ情報
ユーザー属性を作成および調整する
注:いくつかのシナリオの構成を通じて、ユーザー属性の確立と調整を学習および理解します
。Linuxオペレーティングシステムでは、ユーザーの前にグループがあるため、最初にグループを確立する必要があります。
1. class1という名前のグループを作成し、グループIDは1000、class2のグループIDは2000です。
[root@Waffle Desktop]# groupadd class1 建立组
[root@Waffle Desktop]# cat /etc/group
class1:x:501:
[root@Waffle Desktop]# groupmod -g 1000 class1 对class1重新修改组id
[root@Waffle Desktop]# cat /etc/group
class1:x:1000:
[root@Waffle Desktop]# groupadd -g 2000 class2 新建class2,指定组id
class2:x:2000:
2. tomユーザーの確立には、その基本グループがclass1グループであり、追加グループがclass2グループであり、tomユーザーのuidが600である必要があります。
注:ユーザーの作成時に基本グループを指定しない場合、システムはトムグループを直接指定します
[root@Waffle Desktop]# useradd -g class1 tom 新建tom用户 这里写class1也行写1000也行
[root@Waffle Desktop]# id tom 观察tom用户当前信息
uid=501(tom) gid=1000(class1) groups=1000(class1)
[root@Waffle Desktop]# user 按tab后可以查看user开头的命令
useradd userdel userformat userhelper userinfo usermod usermount usernetctl userpasswd users
[root@Waffle Desktop]# usermod -G 2000 -u 600 tom 这里2000写class2也行 指定基本组是-g,-G是指定附加组 -u指定uid
[root@Waffle Desktop]# id tom
uid=600(tom) gid=1000(class1) groups=1000(class1),2000(class2)
3.ユーザーuidが250で、ホームディレクトリのないtestuserという名前のユーザーでプログラムを作成します
。プログラムユーザーの機能:オペレーティングシステムにログインできず、ホームディレクトリがありません。
[root@Waffle Desktop]# useradd -u 250 -M -s /sbin/nologin testuser
-M表示没有家目录
程序用户不能登录系统:-s /sbin/nologin(/sbin/nologin代表这个用户登录时使用的命令解释器,这个就是不允许登录的命令)
[root@Waffle Desktop]# id testuser
uid=250(testuser) gid=2001(testuser) groups=2001(testuser)
[root@Waffle Desktop]# su - testuser 验证不能登录系统
su: warning: cannot change directory to /home/testuser: No such file or directory
This account is currently not available.
[root@Waffle Desktop]# cd /home/ 验证没有家目录
[root@Waffle home]# ls
HSP tom
4. tomユーザーのパスワードを123に設定し、パスワードの最大有効期間を90日に設定し、システムにログインできないようにユーザーパスワードをロックします。
注:パスワードを設定できるのはスーパー管理者のみです。指定されたユーザーの場合
[root@Waffle home]# passwd tom
Changing password for user tom.
New password:
BAD PASSWORD: it is WAY too short
BAD PASSWORD: is too simple
Retype new password:
passwd: all authentication tokens updated successfully.
[root@Waffle home]# cat /etc/shadow 验证
testuser:!!:18683:0:99999:7:::
[root@Waffle home]# man chage
-M, --maxdays MAX_DAYS
Set the maximum number of days during which a password is valid. When MAX_DAYS plus LAST_DAY is less than the
current day, the user will be required to change his/her password before being able to use his/her account.
This occurrence can be planned for in advance by use of the -W option, which provides the user with advance
warning.
Passing the number -1 as MAX_DAYS will remove checking a password´s validity.
[root@Waffle home]# chage -M 90 tom -M后跟密码最长有效期
[root@Waffle home]# id tom
uid=600(tom) gid=1000(class1) groups=1000(class1),2000(class2)
[root@Waffle home]# passwd -S tom -S查看状态
tom PS 2021-02-25 0 90 7 -1 (Password set, SHA512 crypt.)
[root@Waffle Desktop]# passwd -l tom -l锁定tom用户
Locking password for user tom.
passwd: Success
[root@Waffle Desktop]# passwd -S tom
tom LK 2021-02-25 0 90 7 -1 (Password locked.)
[root@Waffle Desktop]# passwd -u tom -u表示unlock 解锁
Unlocking password for user tom.
passwd: Success
5. tomユーザーとtestuserユーザーを削除し、class1グループとclass2グループを削除します
-r的目的是删除这个用户信息的时候连同它的家目录一块删,否则他不会删除它的家目录和它的文件
[root@Waffle Desktop]# userdel -r testuser
userdel: testuser home directory (/home/testuser) not found testuser本来就没有家目录
[root@Waffle Desktop]# user -r tom
bash: user: command not found
[root@Waffle Desktop]# userdel -r tom
[root@Waffle Desktop]# id tom
id: tom: No such user
[root@Waffle Desktop]# groupdel class1
[root@Waffle Desktop]# groupdel class2
ファイルとディレクトリのアクセス許可を調整する
権限ファイルまたはディレクトリが属するユーザー、それが属するグループ、およびさまざまなユーザーがファイルに対して実行できる操作。
次に、tmpディレクトリに2つのファイルを作成します(1つはファイルで、もう1つはディレクトリです)。
[root@Waffle Desktop]# vim /tmp/test.txt
[root@Waffle Desktop]# mkdir /tmp/testdir
[root@Waffle Desktop]# cd /tmp
[root@Waffle tmp]# ls
keyring-L37Uzg virtual-root.IpFBks vmware-fonts-2554.0
orbit-gdm virtual-root.qVMQEf vmware-root
orbit-root vmware-config-11898.0 vmware-root_1301-4248680502
pulse-BULfnWe2TdkQ vmware-config-22916.0 vmware-root_1646-591958445
pulse-M80xbZuu61w5 vmware-config-2554.0 vmware-root_22728-735758538
pulse-ponS681MlrXk VMwareDnD yum.log
testdir vmware-file-mod-11995.0
test.txt vmware-file-mod-1578.0
[root@Waffle tmp]# ls -l test.txt
-rw-r--r--. 1 root root 36 Feb 25 11:44 test.txt
[root@Waffle tmp]# ls -ld testdir 看目录要加d,因为目录没办法直接看它的权限,如果不加d是看它里面内容
drwxr-xr-x. 2 root root 4096 Feb 25 11:44 testdir
[root@Waffle tmp]#
文件:-rw-r--r--. 1(节点) root(所属者) root(所属组) test.txt(前面那个root是用户名,表示这个文件属于哪个用户,后面那个root是组名,表示这个文件属于哪个组)
目录:drwxr-xr-x. 2(文件中的子目录数) root root testdir
.表示这个文件只受到selinux文件程序管理
--rw- r-- r--
d rwx rx rx
フィールド1:ファイルタイプ-通常のファイルを示しますdはディレクトリを示しますlはシンボリックリンクを示しますbはブロックデバイス(ハードディスクなど)を示し
ますフィールド2:ファイルに対するファイル所有者の権限
フィールド3:ファイルはグループ権限に属します
フィールド4:他のユーザーの権限(ファイルの所有者でも、ファイルが属するグループのユーザーでもありません)
r | w | バツ | |
---|---|---|---|
ファイル | 読むファイルを読む | ファイルに書き込む | 実行可能な権限 |
目次 | カタログファイルを表示できます | ファイルを追加または削除できます | カタログに入ることができます |
chmod変更権限
chmodオブジェクト算術演算子のアクセス許可ファイル
オブジェクト:u(所有者)g(グループに属する)o(他のユーザーの権限)a(すべて)
算術演算子:-+ =
権限:rwx(読み取り、書き込み、実行)
例:chmodまたは/tmp/test.txt
ファイルの所有者をtomに、グループをtomに変更します
。groupchownchgrp
chown user file
chgrp group file
[root@Waffle tmp]# chmod o-r /tmp/test.txt
[root@Waffle tmp]# ll /tmp/test.txt
-rw-r-----. 1 root root 36 Feb 25 11:44 /tmp/test.txt
[root@Waffle tmp]# chown tom /tmp/test.txt
[root@Waffle tmp]# chgrp tom /tmp/test.txt
[root@Waffle tmp]# ll test.txt
-rw-r-----. 1 tom tom 36 Feb 25 11:44 test.txt
8進数の重み付け方法:
rwx rw- r-- 764
rwxr ----- 740
使用法:
chmod740ファイル名
注:3つ覚えておいて、他の3つを追加してください。
0 | 000 | -------- |
1 | 001 | - - バツ |
2 | 010 | --w- |
3 | 011 | -wx |
4 | 100 | r ---- |
5 | 101 | 処方箋 |
6 | 110 | rw- |
7 | 111 | rwx |
ファイルの所有者とグループを変更します(chown、chgrp)
chownユーザーファイル
chgrpグループファイル
スティッキービット、sgidパーミッション、suidパーミッション
スティッキービットはディレクトリに権限を割り当て、作成者のみがディレクトリに作成されたファイルを削除できます
创建tom和Jerry两个用户:
[root@Waffle Desktop]# useradd tom
[root@Waffle Desktop]# useradd jerry
创建文件夹并赋权:
[root@Waffle Desktop]# mkdir /tmp/test
[root@Waffle Desktop]# chmod 777 /tmp/test
[root@Waffle Desktop]# ll -d /tmp/test
drwxrwxrwx. 2 root root 4096 Feb 25 16:10 /tmp/test
切换到tom用户 在tmp目录的test文件夹下创建tom.txt文件:
[root@Waffle Desktop]# su tom
[tom@Waffle Desktop]$ cd /tmp/test
[tom@Waffle test]$ touch tom.txt
[tom@Waffle test]$ ll
total 0
-rw-rw-r--. 1 tom tom 0 Feb 25 16:11 tom.txt
[tom@Waffle test]$
登录Jerry用户,问这个文件Jerry能不能删?可以
[tom@Waffle test]$ exit
exit
[root@Waffle Desktop]# su jerry
[jerry@Waffle Desktop]$ cd /tmp/test
[jerry@Waffle test]$ ls
tom.txt
[jerry@Waffle test]$ touch jerry.txt
[jerry@Waffle test]$ ls
jerry.txt tom.txt
[jerry@Waffle test]$ rm -rf jerry.txt
[jerry@Waffle test]$ rm -rf tom.txt
[jerry@Waffle test]$ ls
赋粘滞位:针对目录赋权,目录中创建的文件只有创建者可以删除
[root@Waffle Desktop]# cd /tmp/
[root@Waffle tmp]# chmod o+t test
[root@Waffle tmp]# ll -d test
drwxrwxrwt. 2 root root 4096 Feb 25 16:16 test
[root@Waffle tmp]# su tom
[tom@Waffle tmp]$ cd test
[tom@Waffle test]$ touch tom.txt
[tom@Waffle test]$ exit
exit
[root@Waffle tmp]# su jerry
[jerry@Waffle tmp]$ cd test
[jerry@Waffle test]$ ls
tom.txt
[jerry@Waffle test]$ rm -rf tom.txt
rm: cannot remove `tom.txt': Operation not permitted
[jerry@Waffle test]$ touch jerry.txt
[jerry@Waffle test]$ ls
jerry.txt tom.txt
[jerry@Waffle test]$ rm -rf jerry.txt
[jerry@Waffle test]$
ディレクトリを作成するためのsgidの権限、ディレクトリに作成されたファイルのグループは、親ディレクトリのグループを継承します
[root@Waffle tmp]# chmod g+s test
[root@Waffle tmp]# ll -d test
drwxrwsrwt. 2 root root 4096 Feb 25 16:20 test
[root@Waffle tmp]# su tom
[tom@Waffle tmp]$ cd test
[tom@Waffle test]$ ls
tom.txt
[tom@Waffle test]$ rm -rf tom.txt
[tom@Waffle test]$ touch tom
[tom@Waffle test]$ ll
total 0
-rw-rw-r--. 1 tom root 0 Feb 25 16:26 tom
可以看到这个文件的所属组变成root(所属组会继承父目录的所属组)
suidは実行可能ファイル用に作成されます。suidが確立されている場合、プロセスまたはプログラムを実行するユーザーは、ファイルの所有者のアクセス許可を継承します。
変更されたファイルを実行するユーザーは、ファイルの所有者のアクセス許可を持ちます。
[root@Waffle tmp]# su tom
[tom@Waffle tmp]$ cd /etc
[tom@Waffle etc]$ ll /etc/passwd
-rw-r--r--. 1 root root 1685 Feb 25 16:09 /etc/passwd (TOM能看passwd文件)
[tom@Waffle etc]$ ll /etc/shadow
----------. 1 root root 1092 Feb 25 16:09 /etc/shadow (什么权限都没有)
权限 限制不了超级管理员
[root@Waffle tmp]# which vim
/usr/bin/vim
[root@Waffle tmp]# ll /usr/bin/vim
-rwxr-xr-x. 1 root root 1847752 Apr 5 2012 /usr/bin/vim
[root@Waffle tmp]# chmod u+s /usr/bin/vim
[root@Waffle tmp]# ll /usr/bin/vim
-rwsr-xr-x. 1 root root 1847752 Apr 5 2012 /usr/bin/vim
[root@Waffle tmp]# su tom
[tom@Waffle tmp]$ vim /etc/shadow 查看后把waffle的密码删了,:wq!退出(虽然还是没什么权限,但他依靠root的权限完成了删除)
[tom@Waffle tmp]$ ll /etc/shadow
----------. 1 root root 986 Feb 25 16:42 /etc/shadow
[root@Waffle tmp]# ll -d test
drwxrwsrwt. 2 root root 4096 Feb 25 16:26 test
[root@Waffle tmp]# chmod g-s,o-t test 撤销粘滞位,suid,sgid的方法
[root@Waffle tmp]# ll -d test
drwxrwxrwx. 2 root root 4096 Feb 25 16:26 test
セキュリティ権限
1.新しいユーザーを追加するリクエストは許可されなくなりました
/ etc / group
/ etc / passwd
/ etc / shadow
/ home / xxxxは
変更できません---ロック
chattr + iファイル(ロックを解除するには+ iを-iに変更するだけです)
2、umask
0022
ディレクトリ0777-0022 = 0755の最高機関
ファイルの最高の権限は666-002 = 644です(xは通常指定されていないため、666です)
umaskのディレクトリが022で、ファイルが002である理由は次のファイルにあります。それを制御するifステートメントがあります。
/ etc / profile / etc / bashrc
3.デフォルトパスワードの最大有効期間を変更します
vim /etc/login.defs