1 创建4个用户,密码是12345678

检查环境:

[root@laoliu78 ~]# id

uid=0(root) gid=0(root) groups=0(root)

​[root@laoliu78 ~]# ifconfig | grep inet | awk 'NR==2 {printf $2}'

192.168.1.10[root@laoliu78 ~]#

[root@laoliu78 ~]# hostname -I

192.168.1.10 192.168.122.1 172.17.0.1

以上检查本机的IP 地址,

更新yum 库数据

ping ​​www.baidu.com​​​ [root@laoliu78 ~]# ping ​​​www.baidu.com​​​ PING ​​​www.a.shifen.com​​ (220.181.38.150) 56(84) bytes of data. 64 bytes from 220.181.38.150 (220.181.38.150): icmp_seq=1 ttl=52 time=57.7 ms ^C [root@laoliu78 ~]# yum clean all Loaded plugins: fastestmirror, langpacks, product-id, search-disabled-repos, subscription-manager

This system is not registered with an entitlement server. You can use subscription-manager to register.

Cleaning repos: base epel extras updates Cleaning up list of fastest mirrors [root@laoliu78 ~]# yum repolist Loaded plugins: fastestmirror, langpacks, product-id, search-disabled-repos, subscription-manager

This system is not registered with an entitlement server. You can use subscription-manager to register.

Determining fastest mirrors epel/x86_64/metalink | 3.7 kB 00:00:00

root@laoliu78 opt]# useradd test1

[root@laoliu78 opt]# useradd test12

[root@laoliu78 opt]# useradd test123

[root@laoliu78 opt]# useradd test1234 ----- 创建4个用户

[root@laoliu78 opt]# echo 123456 | passwd --stdin test1

Changing password for user test1.

passwd: all authentication tokens updated successfully.

[root@laoliu78 opt]# echo 123456 | passwd --stdin test12

Changing password for user test12.

passwd: all authentication tokens updated successfully.

[root@laoliu78 opt]# echo 123456 | passwd --stdin test123

Changing password for user test123.

passwd: all authentication tokens updated successfully.

[root@laoliu78 opt]# echo 123456 | passwd --stdin test1234

Changing password for user test1234.

passwd: all authentication tokens updated successfully.

[root@laoliu78 opt]# userdel -r test1

[root@laoliu78 opt]# userdel -r test12

[root@laoliu78 opt]# userdel -r test123-----删除3个用户,留下test1234

​[root@laoliu78 opt]# id test1234

uid=1006(test1234) gid=1006(test1234) groups=1006(test1234)

[root@laoliu78 opt]# vim /etc/passwd

[root@laoliu78 opt]# id test1234

uid=0(root) gid=0(root) groups=0(root)

作业三 设置永久生效的主机命,为什么是永久的

​设置临时用户名为test

[root@urum ~]# hostname test

[root@urum ~]# bash

[root@test ~]# cat /etc/hostname

urum

但是配置文件还是没有改动,主机重启后,恢复原来的urum.

永久修改主机名:

方法一:通过hostnamectl 实现,但是局限是centos 7 以上的版本,

[root@test ~]# hostnamectl set-hostname laoliu78

[root@test ~]#

[root@test ~]# bash

[root@laoliu78 ~]#

方法二:

vim /etc/hostname    此方法需要重启主机,需要重启才能生效

设置临时用户名为test

[root@urum ~]# hostname test

[root@urum ~]# bash

[root@test ~]# cat /etc/hostname

urum

但是配置文件还是没有改动,主机重启后,恢复原来的urum.

永久修改主机名:

方法一:通过hostnamectl 实现,但是局限是centos 7 以上的版本,

[root@test ~]# hostnamectl set-hostname laoliu78

[root@test ~]#

[root@test ~]# bash

[root@laoliu78 ~]#

方法二:

vim /etc/hostname    此方法需要重启主机,需要重启才能生效

购物车脚本

vim tao.sh

#! /bin/bash

echo "请选择需要购买的产品"

echo  "1.apple";echo "2.banana";echo "3.pear";echo "4.table"

[root@laoliu78 ~]# bash tao.sh

请选择需要购买的产品

1.apple

2.banana

3.pear

4.table

[root@laoliu78 ~]#