2023年新版Linux实验报告.docx

上传人:太** 文档编号:72763065 上传时间:2023-02-13 格式:DOCX 页数:20 大小:48.94KB
返回 下载 相关 举报
2023年新版Linux实验报告.docx_第1页
第1页 / 共20页
2023年新版Linux实验报告.docx_第2页
第2页 / 共20页
点击查看更多>>
资源描述

《2023年新版Linux实验报告.docx》由会员分享,可在线阅读,更多相关《2023年新版Linux实验报告.docx(20页珍藏版)》请在taowenge.com淘文阁网|工程机械CAD图纸|机械工程制图|CAD装配图下载|SolidWorks_CaTia_CAD_UG_PROE_设计图分享下载上搜索。

1、Li nux程序设计实验报告姓 名: 杨帆班 级: 计1242学 号:专 业:计算机科学与技术指导老师:赵帼英实验三文献权限管理(必做实验)一、实验目的.熟悉L i nux操作环境。1 .掌握Linux 一般命令格式。2 .理解Lin u x中文献所有者和权限的概念。3 .掌握有关权限操作的常用命令。4 .掌握文献/目录的打包和压缩命令。二、实验内容普通文献与目录权限的修改。1.2.1 改变文献属主。1.2.2 普通文献与目录的打包和压缩。三、。实验环节.文献权限操作1. 1在用户默认工作目录下创建目录te s t 0 3,进入tes t 03目录,使用t ouch命令创建空文献f i lel

2、orootlocalhost fedoral# mkdir test03rootlocalhost fedoral# IsDesktop Documents Download Music Pictures Public Templates test03 test2 test3 Vide( rootlocalhost fedoral# cd test03 rootlocalhost test03# touch filelrootlocalhost test03# Isfilelrootlocalhost test03# a|1. 2显示filel具体信息,记录文献的权限信息,所属用户和组。roo

3、tlocalhost test03# Is -I filel-rw-r-r- 1 root root 0 2015-06-19 19:37 filelrootlocalhost test03#1. 3对filel设立权限,使其他用户可以对此文献进行写操作,并查看设立结rootlocal.host test03# chmod o+w filelrootlocal.host test03# Is -I filel -rw-r-rw- 1 root root 0 2015-06-19 19:37 filel rootlocalhost test03#1 . 4取消同组用户对filel的读取权限,并查

4、看设立结果。rootlocalhost test03# chmod g-r filelrootQlocalhost test03# Is -I filel -rw-rw- 1 root root 0 2015-06-19 19:37 filel rootlocal.host test03#1 . 5用数字形式来为f ile 1设立权限,使所有者可读、可写、可执行;其他用户和所属组用户只有读和执行的权限,并查看设立结果。rootlocalhost test03# chmod 755 filelrootlocalhost test03# Is -I filel -rwxr-xr-x 1 root

5、root 0 2015-06-19 19:37 filel rootlocalhost test03#1.6用数字形式更改filel权限,使所有者只能读取此文献,其他任何用户都没有权限,并查看设立结果。rootlocalhost test03# chmod 400 filelrootlocalhost test03# Is -I filel -r 1 root root 0 2015-06-19 19:37 filelrootlocalhost test03# |7为其他用户添加写权限,并查看设立结果。rootlocalhost test03# chmod o+w filelrootlocal

6、host test03# Is -I filel -r-w- 1 root root 0 2015-06-19 19:37 filelrootlocalhost test03# a|1 . 8回到上层目录,查看test03的权限。rootlocalhost test03# cd .rootlocalhost fedoral# Is -1 test03 total 0-rw- 1 root root 0 2015-06-19 19:37 filelrootlocal.host fedoral#9为其他用户添加对此目录的写权限,查看设立结果。rootlocalhost fedoral# chmod

7、 o+w test03rootlocalhost fedoral# Is -I test03 total 0-rw- 1 root root 0 2015-06-19 19:37 filelrootlocalhost fedoral#1 . 10查看并记录目录te s t 0 3及其中文献的所属用户和组。rootlocalhost fedoral# Is -I test03 total 0rw- 1 root root 0 2015-06-19 19:37 filelrootlocalhost fedoral#1. 11把目录t est03及其下的所有文献的所有者改成bin,所属组改成d a

8、emon,并查看设立结果。rootlocalhost fedoral# chown -R bin:daemon test03rootlocalhost fedoral# Is -I test03 total 0-rw- 1 bin daemon 0 2015-06-19 19:37 filelrootlocalhost fedoral# |1.12删除目录test 03及其下的文献。rootlocalhost fedoral# rm -rf test03rootlocalhost fedoral# IsDesktop Documents Download Music Pictures Publ

9、ic Templates test2 test3 Videos root(atocal.host fedoral# F1 3设定u mask为0 0 0 ($ umask 000),创建testdir目录,并查看其权限。rootlocaLhost tedoralj# unask 000rootlocalhost fedoral# mldir testdir bash: mldir: command not foundrootlocal.host fedoral# mkdir testdirroottaiocalhost fedoral# IsDesktop Documents Download

10、 Music Pictures Public Templates test2 test3Videosrootlocal.host fedoral# Is -1 testdir total 0 rootlocalhost fedoral# |2.打包压缩命令操作2 . 1将/ elc目录拷贝S1J用户默认工作目录下,重命名为etc t es t 0/#/#/# cd home home# Isrootlocalhost rootlocalhost etctestrootlocalhost rootlocalhost etcrootlocalhosthome# cd SU SU# IsS1J# c

11、d etctest etctest# Is etctest#rootlocalhost /# q bash: q: command not found rootlocal.host /# ;bash: syntax error near unexpected token rootlocalhost /# rootlocalhostrootlocalhostrootlocalhost cdd fedora fedoral SU/#/# cd home home# Iscdd fedora fedoral SUrootlocal.host rootlocalhost etctestrootloca

12、lhost rootlocal.host etcrootQlocalhosthome# cd S1JSU# IsS1J# cd etctest etctest# Isetctest#rootlocalhost /# cp -art /etc /home/SU/etctest q rootlocal.host /# q bash: q: command not found rootlocalhost /# ;bash: syntax error near unexpected token rootlocalhost /# rootcatocalhost /# rootcaiocalhostroo

13、tlocalhostrootcaiocalhost2.2 用 tar 命令将 etct e st 目录打包成 etc test, ta r . g z,查看 etct e st . ta r . gz 的权限,解压 缩 etcte s t. tar. g zroot(aiocalhost home# Is etctest etctest.tar.gz fedora root(aiocalhost home# Is -I total 17056 drwxr-xr-x 103rootroot40962015-06-2000:49etctestrootlocalhost home# tar: etc

14、test/rc.d/rc5.d: the futuretar: etctest/rc.d/rc4.d: the futuretar: etctest/rc.d/rc6.d: the futuretar: etctest/rc.d/rc3.d: the futuretar: etctest/rc.d/rc2.d: the futuretar: etctest/rc.d/rc5.d: the futuretar: etctest/rc.d/rc4.d: the futuretar: etctest/rc.d/rc6.d: the futuretar: etctest/rc.d/rc3.d: the

15、 futuretar: etctest/rc.d/rc2.d: the futuretime stamptime stamptime stamptime stamptime stamp2015-06-202015-06-202015-06-202015-06-202015-06-2008:17:54 is08:17:54 is08:17:54 is08:17:54 is08:17:54 is23897.3460323897.3458523897.3455723897.3453S23897.3452tar: etctest/Xll/fontpath.d: time stamp 2015-O6-2

16、0 08:04:22 is 23085.3 in the futuretar: etctest/Xll: time stamp 2015-06-20 08:06:35 is 23218.343903273 suretar: etctest/cron.weekly: time stamp 2015-06-20 08:08:14 is 23317.343C the futuretar: etctest/fonts/conf.d: time stamp 2015-06-20 08:03:24 is 23027.343 n the futuretar: etctest/fonts: time stam

17、p 2015-06-20 08:03:24 is 23027.343233409 uturerootlocalhost home# Isetctest etctest.tar.gz fedoraroot(atocal.host home#四、实验思考题 4. 1列举Is命令不同选项的功能。(1)1 s :显示所有非隐藏文献(按字典顺序排序)(2) Is -a:显示所有文献涉及隐藏文献(3 ) 1s -1:显示所有文献的具体信息(4) 显示总数说明文献权限和文献所有者的含义。-rw-r-r-是文献的权限。Root是用户组。4.2 举例说明umask命令的功能。umask设立了用户创建文献的默认

18、权限,它与c h m o d的效果刚好相反,umask设立的是权限“补码”,而chmod设立的是文献权限码。一般在/c tc/p r ofi 1 e、$ HOME/. b a sh_p r of i le 或SHO ME/, pr o f i le 中设立 uma s k 值。4.3 说明后缀名为tar. gz和t a r. bz2的文献的压缩和解压命令。Lin ux下最常用的打包程序就是t a r 了,使用ta r程序打出来的包我们常称为tar包,ta r包文献的命令通常都是以.tar结尾的。生成t a r包后,就可以用其它的程序来进 行压缩了,所以一方面就来讲讲lar命令的基本用法: ta

19、r命令的选项有很多(用man tar可以查看到),但常用的就那么几个选项,下面 来举例说明一下:# t ar - c f all. t a r *. jpg这条命令是将所有.jpg的文献打成一个名为a 1 1 . tar的包。-c是表达产生新的包,一f指定包的文献名。会# t a r -rf a 1 1. tar *. gif a 这条命令是将所有.gi f的文献增长到al I .tar的包里面去。-r是表达增长文献的a意思。a S ta r - u f all. tar 1 o go. g i f这条命令是更新本来t a r包all.ta r中logo, gif文献,-u是表达更新文献的意思

20、。# ta r -tf a 1 1. ta r这条命令是列出a 1 1. ta r包中所有文献,- t是列出文献的意思# ta r -xf all. tar a这条命令是解出all. t a r包中所有文献,-x是解开的 意思以上就是tar的最基本的用法。为了方便用户在打包解包的同时可以压缩或解压文献,tar 提供了一种特殊的功能。这就是tar可以在打包或解包的同时调用其它的压缩程序。实验结论:通过这个实验我了解了普通文献与目录权限的修改。实验四用户和组的管理(必做实验)一、实验目的.熟悉Linux操作环境。1 .掌握Linux 一般命令格式。2 .熟悉命令行操作方式进行用户和用户组管理。二、

21、。实验内容.建立新用户账号权限测试。2 .为新用户建立账号和工作组,并进行相应配置。3 .以该用户身份登录,修改密码。4 .删除该用户。三、实验环节1.创建用户(以zha n gsan为例)1. 1创建一个新用户zhan gs a n。rootlocal.host home# useradd zhangsanrootlocal.host home# Iscdd etctest etctest. tar.gz fedora federal SU zhangsan rootlocal.host home# |1 . 2查看/ etc / p assw d文献的最后一行内容,并记录。rootatoc

22、alhost home# tail -n 1 /etc/passwd zhangsan:x:502:502:/home/zhangsan:/bin/bash rootlocalhost home#1 . 3查看/ etc/sh a dow文献的最后一行内容,并记录。rootlocalhost home# tail -n 1 /etc/shadowzhangsan:!:16606:0:99999:7:rootlocalhost hornel#1. 4给用户z hangs a n设立密码。root(aiocalhost home# passwd zhangsanChanging password

23、for user zhangsan.New UNIX password:BAD PASSWORD: it is too shortRetype new UNIX password:passwd: all authentication tokens updated successfully. rootlocalhost home#1. 5查看/ e t c/s h a d o w文献的最后一行内容,记录并说明变化。rootlocalhost home# tail -n 1 /etc/shadowzhangsan:$l$NvFS0bqd$Z9.VIP8xpQjKieuX.t9c6/:16606:0

24、:99999:7:rootlocalhost home#. 6使用zha ngsan用户登录系统,测试能否登录成功。rootlocalhost home# su zhangsanzhanqsarKaiocalhost home$1 .创建用户(以us er为例)2 . 1使用1的环节创建新用户useroroot(aiocalhost home# useradd userrootlocalhost home# Iscdd etctest etctest.tar.gz fedora fedoral SU user zhangsan rootlocalhost home# | rootiocamos

25、t nomej# is -itotal 32drwx4 cddcdd40962015-06-1909:14 Cdddrwxr-xr-x103 rootroot40962015-06-1923:48 etctest-rw-r-r-1 rootroot452015-06-2001:15 -rw-r-r-1 rootroot582015-06-1919:11 fedoradrwx26 fedoralfedoral40962015-06-2001:13 fedoraldrwxr-xr-x3 rootroot40962015-06-2000:48 SUdrwx4 useruser40962015-06-

26、2001:52 userdrwx4 zhangsan zhangsan40962015-06-2001:52 zhangsan2. 2更改zh a ngsan所属群组为rootoroottatocalhost home# chgrp root zhangsan rootlocalhost home# Is -1total 32drv/x4 cddcdd4096 2015-06-19 09:14 cdddrv/xr-xr-x103 rootroot4096 2015-06-19 23:48 etctest-rv/- r- - r-1 rootroot45 2015-06-20 01:15 -rv

27、/- r- - r-1 rootroot58 2015-06-19 19:11 fedoradrv/x26 fedoralfedoral4096 2015-06-20 01:13 fedoraldrwxr-xr-x3 rootroot4096 2015-06-20 00:48 SUdrv/x4 useruser4096 2015-06-20 01:52 userd rv/x4 zhanqsanroot4096 2015-06-20 01:52 zhanqsan2. 3查看/ etc/passwd文献,记录z h an g san用户和u ser用户的属组情况。rootlocalhost hom

28、e# tail -n 1 /etc/passwd user:x:503:503:/home/user:/bin/bash rootlocalhost home#2. 4更改用户zhangsa n的帐户名为user。rootlocalhost home# usermod -1 uesr zhangsan usermod: user zhangsan does not existrootlocalhost home# userdel -r useruserdel: /var/spool/mail/user not owned by user, not removing rootlocalhost

29、home# Isedd etetest etetest .tar.gz fedora fedoral SU user2. 5查看/etc / passwd文献的最后一行内容,记录并说明变化。rootlocalhost home# tail -n 1 /etc/passwdedd:x:501:501::/home/edd:/bin/bashrootlocalhost home#2 . 6删除用户user。rootlocalhost home# userdel userrootlocalhost home# Isedd etetest etetest.tar.gz fedora fedoral S

30、1J3.组的管理(以stuff为例)3. 1创建一个新组,组名为stuff。rootlocal.host home# groupadd stuffrootlocal.host home# Isedd etetest etetest .tar.gz fedora fedoral SU user rootlocal.host home# Is -Itotal 28drwx4 eddedd4096 2015-06-1909:14edddrwxr-xr-x103 rootroot4096 2015-06-1923:48etetest-rw-r-r-1 rootroot45 2015-06-2001:1

31、5-rw-r- r-1 rootroot58 2015-06-1919:11fedoradrv/x-26 fedoralfedoral4096 2015-06-2001:13fedoraldrwxr-xr-x3 rootroot4096 2015-06-2000:48S1Jdrwx4503stuff4096 2015-06-2001:52userrootlocalhost home#3. 2查看/etc/g r oup文献的最后一行内容,并记录。rootlocalhost home# tail -n 1 /etc/group stuff:x:503:rootlocalhost home# |3

32、创建一个新帐户t e st,并将其起始组和附属组都设为stuffo实验一 L i nux系统安装与启动一、实验目的(通过实践及查阅资料完毕如下实验).掌握虚拟机的配置过程。1 .掌握L i nux系统的安装过程和简朴配置方法。2 .掌握与Linux相关的多操作系统的安装方法。3 .掌握Linux系统的启动、关闭环节。4 . 了解L i nux文献系统和目录结构。二、。实验内容.安装虚拟机软件(如VMware、Vi r tual b ox)。1 .在虚拟机软件中安装Linux操作系统(如Fed o ra 等)。3,配置Linux系统运营环境。4.对的地启动、关闭系统。三、实验环节.安装虚拟机软件

33、(VMware W o r ksta t i o n 7. 0)1 .在虚拟机软件中新建Linux虚拟机1设立内存大小(建议大于256MB)2.2设立虚拟硬盘大小(建议大于8GB)2. 3设立虚拟光驱(虚拟方式,镜像文献)(选做实验)(选做实验)Ub u n tu、red hat2.4设立网络连接模式(建议采用桥接方式) 2. 5设立共享目录(建议英文目录名)root(aiocalhost home# useradd -g stuff -G stuff testlusergzrootlocalhost home# Iscdd etctest etctest.tar.gz fedora fede

34、ral SU test testlrootlocal.host home# Is -Itotal 36 drv/x4cddcdd40962015-06-1909:14cdddrwxr-xr-x103rootroot40962015-06-1923:48etctest-rw-r-r-1rootroot452015-06-2001:15etctest.tar-rw-r-r-1rootroot582015-06-1919:11fedoradrv/x 26federal fedoral 40962015-06-2001:13federaldrwxr-xr-x3rootroot40962015-06-2

35、000:48SUdrv/x4 testl 504 4096 2015-06-20 02:37 testdrv/x4 testl stuff 4096 2015-06-20 02:39 testldrv/x4503 stuff 4096 2015-06-20 01:52 user3. 4查看/etc/gr o up文献中的最后一行内容,记录并说明变化。rootlocalhost home# tail -n 1 /etc/group stuff:x:503:testlrootlocalhost home#3. 5设立stuf f组密码。rootlocalhost home# gpasswd stu

36、ffChanging the password for group stuffNew Password:Re-enter new password:rootlocal.host homel#3. 6在s t uff组中删除用户t e storootlocalhost home# gpasswd -d testl stuffRemoving user testl from qroup stuff3. 7查看/etc/group文献中的最后一行,记录并说明变化。rootlocalhost home# tail -n 1 /etc/groupstuff:x:503:rootlocalhost hom

37、e#3. 8删除会且stufforootlocal.host home# Is -I total 36drwx4cddcdd40962015-06-1909:14cdddrwxr-xr-x103rootroot40962015-06-1923:48etctest-rw-r-r-1rootroot452015-06-2001:15-rw-r-r-1rootroot582015-06-1919:11fedoradrwx26fedoralfedoral40962015-06-2001:13fedoraldrwxr-xr-x3rootroot40962015-06-2000:48S1Jd rwx4te

38、stlstuffl40962015-06-2002:37testdrwx4testlstuff40962015-06-2002:39testld rwx4503stuff40962015-06-2001:52userrootlocalhost home# groupdel stufflrootlocalhost home#Is -Itotal 36d rwx4cddcdd40962015-06-1909:14cdddrwxr-xr-x103rootroot40962015-06-1923:48etctest-rw-r-r-1rootroot452015-06-2001:15-rw-r-r-1r

39、ootroot582015-06-1919:11fedorad rwx26fedoralfedoral40962015-06-2001:13fedoraldrwxr-xr-x3rootroot40962015-06-2000:48SUdrwx4testl50440962015-06-2002:37testd rwx4testlstuff40962015-06-2002:39testldrwx4503stuff40962015-06-2001:52userrootlocalhost home# |四、实验思考题1 .说明所属群组与所属附加群组的区别。chg r p (chan g e g rou

40、p)改变文献所属群组,h own (change own e r)改变文献所有者属性。2 .如普通用户遗失密码后规定恢复用户权限,说明root用户也许采用的方式。1)在ro o t账户下,打开/ e t c/s h adow (不是passwd文献,由于密码事实上通过加 密后放在了 “影子口令”文献sh a dow中了。pas s wd文献每个用户均可见,但是s h ado w只有root可以见)。2)找到普通用户名cicikasa,然后删除第二个域即可,域之间用“:”隔开的,如下u s er: TdkakkkYU u kkjkjk: 14 6 72:0: 999 9 9:7::上述红色部分就

41、是通过加密的密码,删除即可。3)在普通用户下,输入passwd即可输入新密码。3 .如何指定不同用户的默认工作目录。1) 修改/ e t c/vs f tpd/vsftpd. co n f 将gues t _use r name= v irt u a 1 _ u serus e r con f i g_dir=/etc/v s f tpd_ u seru ser_ s ub_t o k en=$USE R 加进去2)在/etc目录下手工建立v sf t pd_u s er目录3)在/elc/vsf tpd_user目录下建立用户文献,用户文献名称二要登录的用户名。例如:FTP用户是t e st

42、l 1 1那么就在/ e tc/v s f t pd_user /下建立一个t est 111文献, 文献内容 local_root=/home/t e s t 1 1 1 /$US E R4) 重启服务 serv i ce v sftpd restart实验五文本编辑器(选做实验)一、实验目的.掌握Vi编辑器的进入与退出方法。1 . 了解文本编辑器的三种模式。2 .纯熟掌握使用vi编辑器进行编辑、选择及操作文本文献的命令。二、实验内容.进入和退出v io1 .运用文献拷贝方式建立一个文献。2 .在该文献上移动光标位置。3 .对该文献内容执行删除、修改、替换等操作。三、。实验环节.在当前用户默

43、认工作目录下新建一个名为“test02”的目录。1 .将文献 “/etc/syslog. conf 瓮H 到 les t ” 目录下。2 .使用 v i 打开 es t 目录 70勺 rsyslog. c o nfo.指出设定umask (类似于umas k 0022”)的所在行号。3 .将光标移到该行,并复制该行内容。6,将该行内容内容粘贴至最后一行。7 .撤消第6步的动作。8 .光标移到“$ F ileOwner syslog,删除该行。9,存盘但不退出。1().将光标移到首行,插入模式下输入“Hello, thi s is v i world!”。11 .向下查找字符串“syslog”。

44、12 .再向上查找字符串“TCP” o.强制退出vi,不存盘。四、。实验思考题.举例说明实验中使用的命令处在何种模式下?1 .说明在vi中如何实现字符串的查找,并实现查找结果的自动换行。2 .说明在vi中如何实现行号的显示与关闭。实验六库文献的建立与引用(必做实验)按照课本第一章,第7- 1 1页,建立并引用库文献,写出实验过程及结果。库函数介绍:1. Lin ux系统调用,文献的描述符使用的是一个整数,库函数访问文献使用FILE类型的 指针去指向描述文献;库函数不随系统平台而变,即不管win还是Linux都合用;库函数-读文献size _t fr e ad(voi d *ptr, s ize

45、_t size, size_t n, F ILE * st r e am)功能:从stream指向的文献中读取n个字段,每个字段为size字节,并将读取的数据放入 P tr所指向的字符数组中,返I可实际读取的字节数。(读出来的数据量为size*n)库函数-写文献s i z e_t f write (const vo i cl *ptr, s i ze_t size, size_ t n, F ILE *st r e am) 功能:从缓冲区ptr所指向的数组中把n个字段写到stream指向的文献中,每个字段长为size个字节,返回实际写入的字段数。库函数-创建和打开F I LE * f o pen (co n st char *fi 1

展开阅读全文
相关资源
相关搜索

当前位置:首页 > 应用文书 > 解决方案

本站为文档C TO C交易模式,本站只提供存储空间、用户上传的文档直接被用户下载,本站只是中间服务平台,本站所有文档下载所得的收益归上传人(含作者)所有。本站仅对用户上传内容的表现方式做保护处理,对上载内容本身不做任何修改或编辑。若文档所含内容侵犯了您的版权或隐私,请立即通知淘文阁网,我们立即给予删除!客服QQ:136780468 微信:18945177775 电话:18904686070

工信部备案号:黑ICP备15003705号© 2020-2023 www.taowenge.com 淘文阁