Linux系统管理
(1) 用户管理
adduser、useradd、passwd等
xushicheng@ubuntu:/$ sudo adduser testuser #adduser用于新增使用者帐号或更新预设的使用者资料
[sudo] password for xushicheng:
Adding user `testuser' ...
Adding new group `testuser' (1001) ...
Adding new user `testuser' (1001) with group `testuser' ...
Creating home directory `/home/testuser' ...
Copying files from `/etc/skel' ...
Enter new UNIX password:
Retype new UNIX password:
passwd: password updated successfully
Changing the user information for testuser
Enter the new value, or press ENTER for the default
Full Name []:
Room Number []:
Work Phone []:
Home Phone []:
Other []:
Is the information correct? [Y/n] y
xushicheng@ubuntu:/$
root@ubuntu:/# useradd testuseradd #以默认方式创建用户testuseradd
root@ubuntu:/# grep testuseradd /etc/passwd /etc/group /etc/shadow /etc/gshadow
/etc/passwd:testuseradd:x:1002:1002::/home/testuseradd:/bin/sh
/etc/group:testuseradd:x:1002:
/etc/shadow:testuseradd:!:18045:0:99999:7::: #!表示用户未启用或被上锁
/etc/gshadow:testuseradd:!:: //!表示未启用组密码
root@ubuntu:/# passwd -l testuseradd //对testuseradd用户上锁
passwd: password expiry information changed.
root@ubuntu:/# usermod -L testuseradd
xushicheng@ubuntu:/$ su testuseradd //上锁后用户不能再登录系统
Password:
su: Authentication failure
root@ubuntu:/# su testuseradd
$ whoami
testuseradd
$
root@ubuntu:/# passwd -u testuseradd //对用户testuseradd解锁
passwd: unlocking the password would result in a passwordless account.
You should set a password with usermod -p to unlock the password of this account.
root@ubuntu:/# usermod -U testuseradd
usermod: unlocking the user's password would result in a passwordless account.
You should set a password with usermod -p to unlock this user's password.
观察:/etc/passwd文件
xushicheng@ubuntu:/etc$ cat passwd
root:x:0:0:root:/root:/bin/bash
daemon:x:1:1:daemon:/usr/sbin:/bin/sh
bin:x:2:2:bin:/bin:/bin/sh
sys:x:3:3:sys:/dev:/bin/sh
sync:x:4:65534:sync:/bin:/bin/sync
games:x:5:60:games:/usr/games:/bin/sh
man:x:6:12:man:/var/cache/man:/bin/sh
lp:x:7:7:lp:/var/spool/lpd:/bin/sh
mail:x:8:8:mail:/var/mail:/bin/sh
news:x:9:9:news:/var/spool/news:/bin/sh
uucp:x:10:10:uucp:/var/spool/uucp:/bin/sh
proxy:x:13:13:proxy:/bin:/bin/sh
www-data:x:33:33:www-data:/var/www:/bin/sh
backup:x:34:34:backup:/var/backups:/bin/sh
list:x:38:38:Mailing List Manager:/var/list:/bin/sh
irc:x:39:39:ircd:/var/run/ircd:/bin/sh
gnats:x:41:41:Gnats Bug-Reporting System (admin):/var/lib/gnats:/bin/sh
nobody:x:65534:65534:nobody:/nonexistent:/bin/sh
libuuid:x:100:101::/var/lib/libuuid:/bin/sh
syslog:x:101:103::/home/syslog:/bin/false
messagebus:x:102:107::/var/run/dbus:/bin/false
avahi-autoipd:x:103:110:Avahi autoip daemon,,,:/var/lib/avahi-autoipd:/bin/false
avahi:x:104:111:Avahi mDNS daemon,,,:/var/run/avahi-daemon:/bin/false
couchdb:x:105:113:CouchDB Administrator,,,:/var/lib/couchdb:/bin/bash
speech-dispatcher:x:106:29:Speech Dispatcher,,,:/var/run/speech-dispatcher:/bin/sh
usbmux:x:107:46:usbmux daemon,,,:/home/usbmux:/bin/false
haldaemon:x:108:114:Hardware abstraction layer,,,:/var/run/hald:/bin/false
kernoops:x:109:65534:Kernel Oops Tracking Daemon,,,:/:/bin/false
pulse:x:110:115:PulseAudio daemon,,,:/var/run/pulse:/bin/false
rtkit:x:111:117:RealtimeKit,,,:/proc:/bin/false
saned:x:112:118::/home/saned:/bin/false
hplip:x:113:7:HPLIP system user,,,:/var/run/hplip:/bin/false
gdm:x:114:120:Gnome Display Manager:/var/lib/gdm:/bin/false
xushicheng:x:1000:1000:Linux,,,:/home/xushicheng:/bin/bash
testuser:x:1001:1001:,,,:/home/testuser:/bin/bash
testuseradd:x:1002:1002::/home/testuseradd:/bin/sh
(2) 文件系统管理
df、du命令使用
xushicheng@ubuntu:/$ df #df命令用于显示目前在Linux系统上的文件系统的磁盘使用情况统计。
Filesystem 1K-blocks Used Available Use% Mounted on
/dev/sda1 19737268 2289196 16445476 13% /
none 508760 264 508496 1% /dev
none 512992 252 512740 1% /dev/shm
none 512992 88 512904 1% /var/run
none 512992 0 512992 0% /var/lock
none 512992 0 512992 0% /lib/init/rw
xushicheng@ubuntu:/$ df -a #-a, --all 包含所有的具有 0 Blocks 的文件系统
Filesystem 1K-blocks Used Available Use% Mounted on
/dev/sda1 19737268 2289196 16445476 13% /
proc 0 0 0 - /proc
none 0 0 0 - /sys
none 0 0 0 - /sys/fs/fuse/connections
none 0 0 0 - /sys/kernel/debug
none 0 0 0 - /sys/kernel/security
none 508760 264 508496 1% /dev
none 0 0 0 - /dev/pts
none 512992 252 512740 1% /dev/shm
none 512992 88 512904 1% /var/run
none 512992 0 512992 0% /var/lock
none 512992 0 512992 0% /lib/init/rw
vmware-vmblock 0 0 0 - /var/run/vmblock-fuse
binfmt_misc 0 0 0 - /proc/sys/fs/binfmt_misc
gvfs-fuse-daemon 0 0 0 - /home/xushicheng/.gvfs
xushicheng@ubuntu:/$ df -h #-h, --human-readable 使用人类可读的格式
Filesystem Size Used Avail Use% Mounted on
/dev/sda1 19G 2.2G 16G 13% /
none 497M 264K 497M 1% /dev
none 501M 252K 501M 1% /dev/shm
none 501M 88K 501M 1% /var/run
none 501M 0 501M 0% /var/lock
none 501M 0 501M 0% /lib/init/rw
root@ubuntu:/testdu# mkdir testdu
root@ubuntu:/# cd testdu
root@ubuntu:/testdu#
root@ubuntu:/testdu# touch 1
root@ubuntu:/testdu# touch 2
root@ubuntu:/testdu# touch 3
root@ubuntu:/testdu# mkdir aaa
root@ubuntu:/testdu# mkdir bbb
root@ubuntu:/testdu# mkdir ccc
root@ubuntu:/testdu# ls
1 2 3 aaa bbb ccc
root@ubuntu:/testdu# du #du命令用于显示目录或文件的大小。du会显示指定的目录或文件所占用的磁盘空间。
2
3 4 ./ccc
4 4 ./bbb
5 4 ./aaa
6 16 .
mount、umount命令使用:安装usb盘或者光盘,查看分析/etc/fstab文件
root@ubuntu:/# mount /dev/sda1 /testmount #将/dev/sda1 挂载到testmount
root@ubuntu:/# cd testmount
root@ubuntu:/testmount# ls
bin lib mytestunzip.zip srv testln var
boot link2_testln opt sys testmount vmlinuz
cdrom link_testln proc test testtar
dev lost+found root testchmod testunzip
etc media sample.txt testchown testvi
home mnt sbin testdu tmp
initrd.img mytesttar.tgz selinux testgzip.gz usr
root@ubuntu:/# umount -v testmount #通过挂载点卸载testmount
/dev/sda1 umounted
root@ubuntu:/# cd testmount
root@ubuntu:/testmount# ls
root@ubuntu:/testmount#
root@ubuntu:/etc# cat fstab
# /etc/fstab: static file system information.
#
# Use 'blkid -o value -s UUID' to print the universally unique identifier
# for a device; this may be used with UUID= as a more robust way to name
# devices that works even if disks are added and removed. See fstab(5).
#
# <file system> <mount point> <type> <options> <dump> <pass>
proc /proc proc nodev,noexec,nosuid 0 0
# / was on /dev/sda1 during installation
UUID=b4419260-f39f-4924-b956-eec68233bdc6 / ext4 errors=remount-ro 0 1
# swap was on /dev/sda5 during installation
UUID=ec61559a-80ed-4502-8e65-94d1b569540e none swap sw 0 0
/dev/fd0 /media/floppy0 auto rw,user,noauto,exec,utf8 0 0
(3) 存储器
free:了解存储器使用情况
root@ubuntu:/# free #显示内存使用信息
total used free shared buffers cached
Mem: 1025988 424712 601276 0 56700 221392
-/+ buffers/cache: 146620 879368
Swap: 916472 0 916472
root@ubuntu:/# free -m #以MB为单位显示内存使用情况。
total used free shared buffers cached
Mem: 1001 414 587 0 55 216
-/+ buffers/cache: 143 858
Swap: 894 0 894
root@ubuntu:/# free -t #以总和的形式查询内存的信息
total used free shared buffers cached
Mem: 1025988 424704 601284 0 56708 221392
-/+ buffers/cache: 146604 879384
Swap: 916472 0 916472
Total: 1942460 424704 1517756
(4) 关机
halt、shutdown –h、init 0 reboot、shutdown -r now
若系统的 runlevel 为 0 或 6 ,则Linux halt命令关闭系统.
shutdown命令可以用来进行关机程序,并且在关机以前传送讯息给所有使用者正在执行的程序,shutdown 也可以用来重开机。
init 0 :init的运行级别为0表示关机
reboot:重启计算机
shutdown -r now:立即重启
(5) 网络配置
netconfig的使用(详细请参考教材)
root@ubuntu:/# netconfig
netconfig: command not found
root@ubuntu:/# ifconfig
eth0 Link encap:Ethernet HWaddr 00:0c:29:39:da:62
inet addr:192.168.211.128 Bcast:192.168.211.255 Mask:255.255.255.0
inet6 addr: fe80::20c:29ff:fe39:da62/64 Scope:Link
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
RX packets:298 errors:0 dropped:0 overruns:0 frame:0
TX packets:270 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:162280 (162.2 KB) TX bytes:73585 (73.5 KB)
Interrupt:19 Base address:0x2024
lo Link encap:Local Loopback
inet addr:127.0.0.1 Mask:255.0.0.0
inet6 addr: ::1/128 Scope:Host
UP LOOPBACK RUNNING MTU:16436 Metric:1
RX packets:12 errors:0 dropped:0 overruns:0 frame:0
TX packets:12 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:0
RX bytes:720 (720.0 B) TX bytes:720 (720.0 B)
(6)启动配置
/etc/inittab:查看、修改并观察其响应
使用netconfig命令一直无效,没有找到解决办法。。。