Linux simple course design (user, deployment server, firewall [port number])

 Course design content:

 

In the main shell script file (must be named menu.sh) it is necessary to design a menu with multiple operation options for the user to choose from. In the menu, the following functions are automatically implemented:

  1. Create user options. The specific requirement is that when the administrator selects this option, the system allows the administrator to enter the "user name", and then automatically create a Linux common user (the default password is @Linux888).
  2. Deployment server options. The specific requirement is to automatically deploy a certain server service through the yum command; during the deployment process, the installed server version number is displayed.
  3. Modify the server configuration and test using the server. .
  4. Firewall configuration options. The specific requirement is that when the administrator selects this option, the system allows the administrator to input the "port number" and "on/off" operation, and the system opens or closes the specified port number according to the administrator's input.
  5. Exit System Options. The specific requirement is that the system exits after the administrator selects this option.

 Chinese abstract

This article mainly introduces several key technologies such as HTTPD server configuration, Shell programming, firewall design and personal home page realization. First of all, HTTPD server is a kind of software used to provide web services. This article discusses how to configure HTTPD, including how to modify HTTPD configuration files and how to start and stop HTTPD services. Secondly, this article also introduces the basic knowledge and common commands of Shell programming, and how to use Shell scripts to achieve some simple tasks. Then, this article explains the importance of firewall design and how to use iptables to configure firewall rules to protect the security of the server. Finally, this article also introduces how to implement a personal homepage, with the character "*" plus numbers and Chinese characters as options. In short, this article is rich in content and covers a number of key technologies, which has certain reference value for readers who want to have a deep understanding of Web server and network security.

Keywords: HTTPD Configuration Shell Programming Firewall Design Personal Homepage Realization

 

Curriculum Design Purpose

"Linux Operating System" is a professional elective course for computer science and technology related majors. The course design is one of the concentrated practical links, and it is a comprehensive comprehensive exercise after completing the study of this course. Its purpose is to deepen the understanding and application of basic commands of the Linux operating system, Shell programming, key service deployment and development, network security, etc. For this reason, the course design involves the content of the above-mentioned links, requiring students to complete the whole process of analysis, design, configuration, and testing of a Linux operating system project, and initially have the basic ability to use the Linux operating system, and strengthen various aspects of the course learning. Comprehensive application of knowledge and practical experience.

 Fundamentals of required knowledge

 Introduction to Shell Commands and Programming

Shell is a command line interpreter that can be used to execute various system commands and scripts. Shell programming is a scripting programming language that can be used to write scripts for automation tasks and data processing. Shell is a program written in C language, which is a bridge for users to use Linux. Shell is both a command language and a programming language. Shell refers to an application program that provides an interface through which users access the services of the operating system kernel

Introduction to User Management

Linux user management refers to the management of user accounts in the Linux operating system, including operations such as creation, modification, deletion, and authorization. In the Linux system, each user has a unique user ID (UID) and a group ID (GID), and the user can belong to one or more groups. User permissions and access control are implemented based on these IDs. Linux user management tools include command line tools and graphical interface tools. The most commonly used command line tools include useradd, usermod, userdel, passwd, etc. These commands can implement different functions through command line parameters, such as creating users and modifying user information. , delete users, change passwords, etc. In addition to basic user management, the Linux system also supports access control and rights management to implement more complex user authentication and access control schemes.

Introduction to Firewall

A firewall is a network security device that monitors and controls traffic entering and leaving a network. It can filter network traffic, block or allow specific traffic to pass according to preset rules and policies. Firewalls help protect computers and networks from malicious attacks, such as Internet viruses, hacking, and malware. It can also be used to control user access to specific websites and applications to maintain the security and stability of corporate networks. Firewall usually has two forms of hardware and software, and is widely used in the network security protection of enterprises, government agencies and individual users.

Introduction to HTTPD Server

httpd is the official name of Apache HTTP Server, which is an open source web server software. It is one of the most popular web servers out there and supports multiple operating systems, including Linux, Windows, macOS, and more. Apache HTTP Server supports multiple protocols such as HTTP, HTTPS, and FTP, and has the advantages of high reliability, excellent performance, and strong scalability. It is widely used in the Internet, corporate internal networks, and personal websites. At the same time, Apache HTTP Server also supports a variety of modules and plug-ins, which can realize advanced functions such as reverse proxy, load balancing, security authentication, etc.

 System flow chart

 

4.3 Function realization

main menu page

Figure 4.3.1 Main menu map

Select 1 under the authority of the administrator to automatically create users

Figure 4.3.2 Create user map

Choose 2, enter httpd, and automatically deploy the httpd server to display the server name and version number (it has been installed before)

Figure 4.3.2 Deployment server diagram

 

Select 3, enter the user name to be deleted, and delete the user automatically

Figure 4.3.3 Delete User Map

Choose 4, change the port of httpd to 8080 and restart the test server to see if it is normal

Figure 4.3.4 Modify server map

Select 5, enter the port number, enter on to open port 8080

 

Figure 4.3.5 Firewall settings diagram

Choose 6, exit the system

 

Figure 4.3.5 Exit system diagram

Course Design Summary

After the design of this course, I learned a lot about the implementation and setting of creating user options, deploying server options, modifying server configuration and testing the use of the server, firewall configuration options, and exiting system options.

Let me have a certain understanding of Linux. I know that Linux is just a kernel. The current Linux operating system is composed of such a kernel plus other applications. The biggest feature of Linux is its open source, which is very rare, and this is one of the reasons why it can exist until now, making it have very important applications in financial, security and other departments.

To learn Linux, we should first learn from the basics. Have a more comprehensive understanding of the functions, versions, and features of the Linux operating system, as well as the installation and graphics environment of the Linux system. Linux commands are a must to learn. Although Linux desktop applications are developing rapidly, commands still have a strong vitality in Linux. Linux is an operating system composed of command lines. The essence lies in the command line. Learn how to execute system commands in a safe environment, including concepts such as files, directories, file systems, and processes, and how to use corresponding commands to execute files, directories, and processes. etc. to manage and understand how to find help information when encountering problems. Common Linux commands include echo command, date command, passwd command, file command, ls command, touch command, etc.

Create user options, deploy server options, modify server configuration and test using the server, firewall configuration options, exit system options

Below the source code

#! /bin/bash

function show()
{
clear;
echo "****************************************************************************";
echo "***                       欢迎使用用户管理系统                            ***";
echo "***                    1 : 创建用户                                      ***";
echo "***                    2 : 部署服务器                                    ***";
echo "***                    3 : 删除用户                                      ***";
echo "***                    4 : 修改httpd服务器                               ***";
echo "***                    5 : 防火墙配置                                    ***";
echo "***                    6 : 退出系统                                      ***";
echo "****************************************************************************";
echo "请为您需要的功能选择号码!";
echo "请输入你的选择:";
}

function Create_users()
{
read -p "请输入要创建的用户名:" username

# 判断用户是否已存在
if id "$username" >/dev/null 2>&1; then
    echo "用户 $username 已存在!"
    exit 1
fi

# 创建用户
useradd -m "$username"

# 设置默认密码
echo "$username:@Linux888" | chpasswd

# 输出创建结果
if id "$username" >/dev/null 2>&1; then
    echo "用户 $username 创建成功!默认密码为 @Linux888"
else
    echo "用户 $username 创建失败!"
fi
}

function Deploying_servers()
{
    # 输入要部署的服务名
read -p "请输入要部署的服务名:" service_name

# 使用yum安装服务
yum install -y $service_name

# 显示安装的版本号
version=$(yum list installed $service_name | grep -oP '\d+\.\d+\.\d+')
echo "已安装 $service_name 版本号为 $version"
}

function Delete_a_user()
{
       user="$1"
 
    userdel "$user" # 删除用户
     
    if [[ "$?" == 0 ]];
       then
        echo "已经删除${user}用户"
    fi
}

function Modify_server()
{
# 修改httpd.conf配置文件
sed -i 's/Listen 80/Listen 8080/g' /etc/httpd/conf/httpd.conf

# 重启httpd服务
systemctl restart httpd

# 测试服务器是否正常工作
if curl -s localhost | grep -q 'server is running'; then
  echo "Server is working properly"
else
  echo "Server is not working properly"
fi
}


function Fire_wall(){
# 判断是否为管理员
if [[ $EUID -ne 0 ]]; then
echo "请使用管理员权限运行该脚本!"
exit 1
fi

# 获取管理员输入的端口号和操作(on/off)
read -p "请输入端口号:" port
read -p "请输入操作(on/off):" action

# 判断操作是否合法
if [ $action != "on" ] && [ $action != "off" ]
then
    echo "操作不合法,只能输入 on 或 off"
    exit 1
fi

# 开启或关闭指定的端口号
if [ $action == "on" ]
then
    firewall-cmd --zone=public --add-port=$port/tcp --permanent
    firewall-cmd --reload
    echo "端口号 $port 已开启"
else
    firewall-cmd --zone=public --remove-port=$port/tcp --permanent
    firewall-cmd --reload
    echo "端口号 $port 已关闭"
fi
}

function Quit()
{
                        echo "Bye bye!";
                        exit 0;
}

function main()
{
for i in $(seq 1 100)
do
show;
read choice;
case $choice in
        1)Create_users;;
        2)Deploying_servers;;
        3)
	read -p "请输入需要删除的用户名:" uname
	Delete_a_user "$uname"
	;;
        4)Modify_server;;
        
	5)Fire_wall;;
	6)Quit;;
	*)echo "Incorrect input!";;
esac
read delay;
if [ $i -eq 100 ];
then
        echo "error";
        clear;
        break;
fi
done
}
main;

Guess you like

Origin blog.csdn.net/qq_72505850/article/details/130947888