linux基础,linux基础入门


基本命令的讲解

1) 掌握关闭Linux系统的命令:init 0

#关机

   init 0  

2) 掌握什么是Linux终端:Linux终端也称为虚拟控制台。Linux终端采用字符命令行方式工作,用户通过键盘输入命令,通过Linux终端对系统进行控制。


3) 掌握切换虚拟终端的方法:Ctrl+Alt+F[1~6],如想切换到第二号虚拟终端,则同时按Ctrl+Alt+F2


4) 掌握普通用户登录后系统的提示符:$


5) 掌握root用户登录后系统的提示符:#

 

6) 掌握退出命令:exit

exit 退出终端

ps:

[root@study tmp]# exit
logout

 

1. Linux命令的格式(详见linux系统管理P23)
1) 了解Linux命令的语法格式:
命令 【选项】 【参数】
2) 掌握命令格式中命令、选项、参数的具体含义
a) 命令:告诉Linux(UNIX)操作系统做(执行)什么。

b) 选项:说明命令运行的方式(可以改变命令的功能)。选项部分是以“-”字符开始的。
c) 参数:说明命令影响(操作)的是什么(如一个文件、一个目录或是一段正文文字)


Ls –a /    #显示根目录下的所有文件,包括隐藏文件

[root@study ~]# ls -a /
. .autofsck bin dev home lib64 media opt root selinux sys usr
.. .autorelabel boot etc lib lost+found mnt proc sbin srv tmp var

 

2. whoami命令(详见linux系统管理P24)
1) 了解whoami命令的功能:列出目前登陆Linux系统所使用的用户名(账号)。

ps:

[root@study ~]# whoami
root


3. who命令(详见linux系统管理P25)

1) 掌握who命令的功能:列出目前哪些用户在系统上工作。

ps

[root@study ~]# who
root tty1 2016-11-09 10:57
root pts/0 2016-11-10 09:18 (192.168.11.5)
root pts/1 2016-11-10 11:38 (192.168.11.5)


2) 掌握who命令的输出结果:显示当前登录的所有用户,以及当前的日期和时间。

ps

[root@study ~]# who
root tty1 2016-11-09 10:57
root pts/0 2016-11-10 09:18 (192.168.11.5)
root pts/1 2016-11-10 11:38 (192.168.11.5)


4. date、cal、和clear命令及带有参数的命令

(详见linux系统管理P28-P29)

 

cal 显示某月的日历。

ps:

[root@study ~]# cal
十一月 2016 
日 一 二 三 四 五 六
1 2 3 4 5
6 7 8 9 10 11 12
13 14 15 16 17 18 19
20 21 22 23 24 25 26
27 28 29 30

 

date 显示日期和时间

ps:

[root@study ~]# date
2016年 11月 10日 星期四 09:36:29 CST

 

clear 清除屏幕信息

[root@study ~]# clear

 

清屏快捷键:ctrl+l

 

2) 掌握date命令设置时间时间的格式:date 月日时分年。

例如:将时间设定成2013年12月24日上午10点18的命令:
扩展(date 12241018201


hwclock –s 同步硬件 –w 同步系统)

ps:

[root@study ~]# hwclock -s
[root@study ~]# hwclock
2016年11月10日 星期四 09时54分01秒 -0.451867 seconds

 

4) 灵活应用cal命令列出某一年某月的日历:例如显示2008年8月份日历的命令为:cal 8 2008

ps:

[root@study ~]# cal 8 2008
八月 2008
日 一 二 三 四 五 六
1 2
3 4 5 6 7 8 9
10 11 12 13 14 15 16
17 18 19 20 21 22 23
24 25 26 27 28 29 30
31

 

5. su和passwd命令(详见linux系统管理P29-P31)
1) 掌握su命令的功能:从当前的用户切换到另一个指定的其他用户。

ps:

[root@study ~]# su - nulige
[nulige@study ~]$


2) 灵活应用su命令切换用户:
例如:切到root用户的命令:su – root

 

3) 掌握passwd命令功能:修改用户(既可以是普通用户,也可以是root用户)的密码,查看用户的密码状态等。Useradd

[root@study ~]# passwd nulige
更改用户 nulige 的密码 。
新的 密码:
无效的密码: 它基于字典单词
重新输入新的 密码:
passwd: 所有的身份验证令牌已经成功更新。

 

4) 掌握使用passwd命令修改用户密码:
例如:修改dog用户密码的命令:passwd dog

ps:

[root@study ~]# passwd dog
更改用户 dog 的密码 。
新的 密码:
无效的密码: 它基于字典单词
重新输入新的 密码:
passwd: 所有的身份验证令牌已经成功更新。

6. 利用man命令来获取帮助信息(详见linux系统管理P34)

1) 掌握man命令的功能:获取某个Linux命令的使用说明。
2) 掌握使用man命令查看某命令的使用说明:

例如:查看su命令的使用说明的命令为:man su

ps:

[root@study ~]# man su
SU(1) User Commands SU(1)

NAME
su - run a shell with substitute user and group IDs

SYNOPSIS
su [OPTION]... [-] [USER [ARG]...]

DESCRIPTION
Change the effective user id and group id to that of USER.

-, -l, --login
make the shell a login shell, clears all envvars except for TERM, initial-
izes HOME, SHELL, USER, LOGNAME and PATH

-c, --command=COMMAND
pass a single COMMAND to the shell with -c

--session-command=COMMAND
pass a single COMMAND to the shell with -c and do not create a new session

-f, --fast
pass -f to the shell (for csh or tcsh)

-m, --preserve-environment
do not reset HOME, SHELL, USER, LOGNAME environment variables

-p same as -m

 

7. 使用“命令名 --help”获取帮助
1) 例如:查看ls命令帮助的命令为:(不使用man方法)
ls --help

ps:

[root@study ~]# ls --help
用法:ls [选项]... [文件]...
列出 FILE 的信息(默认为当前目录)。
如果不指定-cftuvSUX 或--sort 选项,则根据字母大小排序。

长选项必须使用的参数对于短选项时也是必需使用的。
-a, --all 不隐藏任何以. 开始的项目
-A, --almost-all 列出除. 及.. 以外的任何项目
--author 与-l 同时使用时列出每个文件的作者
-b, --escape 以八进制溢出序列表示不可打印的字符
--block-size=大小 块以指定大小的字节为单位
-B, --ignore-backups 不列出任何以"~"字符结束的项目
-c 配合-lt:根据ctime 排序并显示ctime(文件
状态最后更改的时间)
配合-l:显示ctime 但根据名称排序


8. 课后作业(用时30分钟)
1) 要求以root用户登录系统,右击桌面打开终端,查看当前登陆Linux系统所使用的用户名

ps:

[root@study ~]# whoami
root


2) 查看哪些用户在系统上工作

[root@study ~]# who
root tty1 2016-11-09 10:57
root pts/0 2016-11-10 09:18 (192.168.11.5)
root pts/1 2016-11-10 11:38 (192.168.11.5)


3) 修改当前时间为2018年8月26号11:28

[root@study ~]# date -s 08/26/2018
2018年 08月 26日 星期日 00:00:00 CST


[root@study ~]# date -s 11:28:00
2018年 08月 26日 星期日 11:28:00 CST

 

4) 查看2015年10月份日历

ps:

[root@study ~]# cal 10 2015
十月 2015
日 一 二 三 四 五 六
1 2 3
4 5 6 7 8 9 10
11 12 13 14 15 16 17
18 19 20 21 22 23 24
25 26 27 28 29 30 31


5) 使用两种方法查看ls命令的使用说明

[root@study ~]# ls -l
总用量 56
-rw-------. 1 root root 1237 9月 8 19:18 anaconda-ks.cfg
-rw-r--r--. 1 root root 21682 9月 8 19:18 install.log
-rw-r--r--. 1 root root 5890 9月 8 19:18 install.log.syslog
-rw-r--r--. 1 root root 13224 9月 8 19:22 system_optimize_scripts.sh


[root@study ~]# ls
anaconda-ks.cfg install.log install.log.syslog system_optimize_scripts.sh


6) 清除屏幕

clear  ctrl + l


7) 使用“useradd tom”命令新建tom用户,为tom用户设置密码“123”

useradd tom

passwd 123

 

8) 切换当前用户为tom

su - tom


9) 查看当前登陆Linux系统所使用的用户名

[root@study ~]# whoami
root

 


第六单元 用户、群组和权限

用户及passwd文件
/etc/passwd文件的功能
/etc/passwd文件每个字段的具体含义

ps:
nologin #不可登录
/bin/bash #可登录

daemon:x:2:2:daemon:/sbin:/sbin/nologin
nologin #不可登录

oldboy :x:501:501::/home/oldboy:/bin/bash
/bin/bash #可登录

nulige:x:500:500::/home/nulige:/bin/bash
用户名+密码+用户UID:GID 用户家目录 可登录

nulige: :500:500::/home/nulige:/bin/bash
:: 表示没有密码,可以直接登录系统

特点:
500以前的是系统用户
普通用户的UID和GID 是从500开始

nulige: :0:500::/home/nulige:/bin/bash
0 uid 就是root用户


shadow文件
/etc/shadow文件的功能
/etc/shadow文件每个字段的具体含义
ps:

shadow 作用是:存放密码
[root@study ~]# cat /etc/shadow
root:$6$HJdW8nJO$ILP4OTkWE/Q6sGFRCI4CFQnpMhsNAWGy0/qjnYH99vYjJjSihqqDKLmnzcsCFZwTD5jyZ7pobu45.n3lNx3pL/:17115:0:99999:7:::
bin:*:15980:0:99999:7:::
daemon:*:15980:0:99999:7:::
adm:*:15980:0:99999:7:::
lp:*:15980:0:99999:7:::


群组及group文件
/etc/group文件的功能
/etc/group文件的功能

ps:
[root@study ~]# less /etc/group
root:x:0:
root组:组ID号

nulige:x:500:
oldboy:x:501:
lenovo:x:502:
用户名:x密码占位符:组ID

组密码文件
[root@study ~]# cat /etc/gshadow
root:::
bin:::bin,daemon
daemon:::bin,daemon
sys:::bin,adm
adm:::adm,daemon
tty:::
disk:::
lp:::daemon


怎样在Linux系统中添加一个新的用户账户
useradd命令的功能
useradd命令的常用选项
useradd命令的用法举例

#创建用户
[root@study ~]# useradd huzhihua

#用户家目录配置文件
[root@study ~]# ls /home/huzhihua/ -a
. .. .bash_logout .bash_profile .bashrc

[root@study ~]# ls /etc/passwd
/etc/passwd

[root@study ~]# ls /etc/shadow
/etc/shadow

[root@study ~]# ls /etc/group
/etc/group

[root@study ~]# ls /etc/gshadow
/etc/gshadow

[root@study ~]# ls /var/spool/mail/nulige
/var/spool/mail/nulige

[root@study ~]# ls /home/
huzhihua lenovo nulige oldboy

#查看用户的详细信息
[root@study ~]# id nulige
uid=500(nulige) gid=500(nulige) 组=500(nulige)
(nulige) 组用户

uid=500(nulige) gid=500(nulige) 组=500(nulige),组501(test)
(nulige) 组用户 一个人可以同时在多个组中


#删除用户
userdel -r nulige

tail -1 /etc/passwd
id nulige

#修改用户
useradd alex
id alex
ls /home/alex
ls /home
tail -1 /etc/passwd

 

使用usermod命令修改用户账户
usermod命令的功能
更改用户配置文件,但要创建一个配置文件,把文件配置文件复制过来。
usermod命令修改用户账户信息时的常用选项
usermod命令的用法举例
使用usermod命令锁住用户及将用户解锁
usermod –L命令
usermod –U命令
使用userdel命令删除用户账号
userdel命令的功能
userdel的常用选项
userdel的用法举例
群组的管理
groupadd命令的功能
groupadd命令的常用选项
groupadd命令的用法举例
groupmod命令的功能
groupmod命令的常用选项
groupmod命令的用法举例
groupdel命令的功能
groupdel命令的用法举例


[root@study ~]# su - lenovo
[lenovo@study ~]$ su -
密码:
[root@study ~]# su - nulige
-bash-4.1$
-bash-4.1$
-bash-4.1$
-bash-4.1$ su -
密码:
[root@study ~]# cp -r /home/lenovo/.[!.]* /home/nulige
[root@study ~]# su - nulige
[nulige@study ~]$
[nulige@study ~]$
[nulige@study ~]$


ps:
[root@study ~]# tail -4 /etc/passwd
nulige:x:500:500::/home/nulige:/bin/bash
oldboy:x:501:501::/home/oldboy:/bin/bash
lenovo:x:502:502::/home/lenovo:/bin/bash
huzhihua:x:503:503::/home/huzhihua:/bin/bash

[root@study ~]# id lenovo
uid=502(lenovo) gid=502(lenovo) 组=502(lenovo)

[root@study ~]# id huzhihua
uid=503(huzhihua) gid=503(huzhihua) 组=503(huzhihua),502(lenovo)


[root@study ~]# id nulige
uid=500(nulige) gid=500(nulige) 组=500(nulige)

[root@study ~]# usermod -aG huzhihua nulige
[root@study ~]# id nulige
uid=500(nulige) gid=500(nulige) 组=500(nulige),503(huzhihua)

[root@study ~]# usermod -aG lenovo nulige
[root@study ~]# id nulige
uid=500(nulige) gid=500(nulige) 组=500(nulige),502(lenovo),503(huzhihua)

 

 


 

 

准备两个用户tom,jack
实验一:
su - tom
cd /tmp
新建文件tom.txt
查看tom.txt的权限信息
修改其他人对tom.txt的权限,然后su - jack 逐一验证效果:

答案:

[root@study ~]# useradd tom
[root@study ~]# passwd tom
更改用户 tom 的密码 。
新的 密码:
无效的密码: 它基于字典单词
重新输入新的 密码:
passwd: 所有的身份验证令牌已经成功更新。

[root@study ~]# useradd jack
[root@study ~]# passwd jack
更改用户 jack 的密码 。
新的 密码:
无效的密码: 它基于字典单词
重新输入新的 密码:
passwd: 所有的身份验证令牌已经成功更新。

su - tom
cd /tmp
touch tom.txt
[tom@study tmp]$ chmod o=- tom.txt

[tom@study tmp]$ ll tom.txt
-rw-rw---- 1 tom tom 0 11月 10 15:20 tom.txt

[tom@study tmp]$ su -
密码:
[root@study ~]# usermod -aG tom jack

[root@study ~]# id jack
uid=506(jack) gid=507(jack) 组=507(jack),506(tom)

[root@study ~]# su - jack
[jack@study ~]$ cd /tmp
[jack@study tmp]$ ll
总用量 8
-rwxr--r-- 1 root root 0 11月 10 14:29 a.txt
-rw-rw-r-- 1 nulige nulige 0 11月 10 14:32 lhf.txt
drwx------ 2 root root 4096 11月 10 09:18 ssh-HYhuU26587
drwxr-xr-x 2 root root 4096 11月 10 14:24 test
-rw-r--r-- 1 root root 0 11月 10 09:44 test01.txt
-rw-r--r-- 1 root root 0 11月 10 09:46 test02.txt
-rw-rw---- 1 tom tom 0 11月 10 15:20 tom.txt
[jack@study tmp]$ echo 11111111111111 >tom.txt
-bash: tom.txt: 权限不够

实验二:
把jack添加到tom组里
su - tom
cd /tmp
修改属组对tom.txt的权限,然后su - jack 逐一验证效果

[tom@study tmp]$ su -
密码:
[root@study ~]# usermod -aG tom jack
[root@study ~]# id tom
uid=505(tom) gid=506(tom) 组=506(tom)
[root@study ~]# id jack
uid=506(jack) gid=507(jack) 组=507(jack),506(tom)

[root@study ~]# su - tom

[tom@study ~]$ cd /tmp/

[tom@study tmp]$ echo 222222222222222 >>/tmp/tom.txt
[tom@study tmp]$ cat tom.txt
11111111111111
222222222222222

[tom@study tmp]$ chmod g=- tom.txt
[tom@study tmp]$ ll tom.txt
-rw------- 1 tom tom 31 11月 10 15:33 tom.txt

[root@study ~]# su - jack
[jack@study ~]$ cd /tmp/

[jack@study tmp]$ ll tom.txt
-rw------- 1 tom tom 31 11月 10 15:33 tom.txt
[jack@study tmp]$ echo 3333333333 >>tom.txt
-bash: tom.txt: 权限不够

 

实验三:
su - tom
cd /tmp
修改其他人对tom.txt的权限信息,然后su - root 逐一验证root 用户到底受不受权限限制。

[root@study ~]# su - tom
[tom@study ~]$ cd /tmp

[tom@study tmp]$ ll tom.txt
-rw------- 1 tom tom 31 11月 10 15:33 tom.txt

[tom@study tmp]$ chmod o+r tom.txt

[tom@study tmp]$ ll tom.txt
-rw----r-- 1 tom tom 31 11月 10 15:33 tom.txt

[root@study tmp]# echo 4444444 >>tom.txt
[root@study tmp]# cat tom.txt
11111111111111
222222222222222
4444444

 

相关内容

    暂无相关文章