Common Linux commands and server configurations

Source: Internet
Author: User
Common Linux commands and server configurations-Linux Enterprise applications-Linux server application information. For details, refer to the following section. Transfer
1. Add User useradd command

Example:

# Useradd? M? G users? G wheel, sales? S/bin/tcsh? C "a user" myname

# Useradd-c "ftp Administrator"-d/var/ftp/-G ftpAdmin-s/sbin/nologin-r ftpAdmin

-M automatically creates the user's home directory and copies the framework directory (/etc/skel) file to the user directory.

-G: set the basic group in which the user is located.

-G adds the user to all comma-separated groups.

-S specifies the shell used.

-C description.

-D: set the main directory for the account.

-R system account. You do not need to create a home directory in/home.

The last one is the user name.

Ii. Specify the password passwd

Example: # passwd User Name

Enter the password.

3. delete user userdel

Example: # userdel Username

# Userdel? R user name

-R: Delete the home Directory (/home /.....)

Iv. File System commands

4.1 fdisk command

(1) fdisk? L: displays all partitions on the hard disk. Partition type (FAT32, Ext3 ).

(2) df? H: shows how the file system is mounted.

(3) fdisk/dev/hdb1: format the second IDE disk.

4.2 mount command mount the File System

(1) mount (no parameters are used) to view the system mounting status.

(2) mount/mnt/cdrom: mount the optical drive. You can use the cd/mnt/cdrom and then ls to view the content on the optical drive.

(3) mount/mnt/floppy: mount a floppy disk. You can use cd/mnt/floppy to check the content on the floppy disk.

In steps 2 and 3, you can use/dev/cdrom and/dev/fd0 to replace the mount point and get the same effect!

(4) mount? T msdos/dev/fd0/mnt/floppy: mount the DOS floppy disk to/mnt/floppy.

(5) mount Windows partitions

# Fdisk-l: List hard disk partitions.

# Mkdir/mnt/win: create a directory for mounting.

# Mount-t vfat/dev/hda1/mnt/win: Suppose Windows is in the first partition of the first IDE hard disk.

Note: can be used? T auto parameter makes the system automatically monitor the file type!

-R is mounted in read-only mode.

-W read/write mounting.

4.3 umount command uninstall the File System

(1) umount/mnt/floppy detach the device (such as/dev/fd0) from the mount point/mnt/floppy. You can also do this by umount/dev/fd0

To make the partition permanently available for Linux, add the following line to the/etc/fstab file:

/Dev/hda1/mnt/win vfat defaults 0 0

V. File-related commands

5.1 File Permission chmod

Example:

Chmod 777 files-> rwxrwxrwx

Chmod 755 files-> rwx r-x

Chmod 644 files-> rw--r-

Chmod 000 files-> -〉---------

Chmod u + x g + w o + r file (give the file the right to be executable by the owner, writable by the same group, and read by others)



$ Chmod? R 777/tmp/test: Change the permissions of all files and directories in the directory (all permissions ).

$ Chmod? R 664/tmp/test: Disable the execution permission.

5.2 File Ownership

Chown user1 file (allocate file to user1)

5.3 mobile file mv

Example: mv abc def in this file abc moved its name to def.

Vi. View iptables commands

Internet: eth0 123.45.67.89

Intranet: the IP addresses of computers on the eth1 10.0.0.1 LAN are all in 10.0.0.2 ~~ 10.0.0.254.

(1) In an rc. local example, add the following command to rc. local:

Echo 1>/proc/sys/net/ipv4/ip_forward # Start IP Forwarding

Echo 1>/proc/sys/net/ipv4/ip_dynaddr # Start a dynamic IP Address

# Reject ies (Default) sets the Default policy to reject

Iptables-P INPUT DROP

Iptables-P OUTPUT DROP

Iptables-P FORWARD DROP

# User-defined chain for ACCEPTed TCP packets User-defined chain named "okay"

Iptables-N okay

Iptables-A okay? P TCP-syn? J ACCEPT

Iptables-A okay? P TCP-m state-state ESTABLISHED, RELATED? J ACCEPT

Iptables-A okay? P TCP? J DROP

# INPUT chain rules

# Rules for incoming packets from LAN

Iptables-a input-p ALL-I eth1-s 10.0.0.0/8-j ACCEPT # the address in the LAN is acceptable

Iptables-a input-p ALL-I lo-s 127.0.0.1-j ACCEPT # ACCEPT packets

Iptables-a input-p ALL-I lo-s 10.0.0.1-j ACCEPT # ACCEPT packets

Iptables-a input-p ALL-I lo-s 123.45.67.89-j ACCEPT # ACCEPT packets

Iptables-a input-p ALL-I eth1? D 10.0.0.255-j ACCEPT # ACCEPT broadcast packets in the LAN

# Rules for incoming packets from the Internet

# Packets for established connections

Iptables-a input-p ALL-d 123.45.67.89-m state? State ESTABLISHED, RELATED? J ACCEPT

# TCP rules is processed by the okay chain

Iptables-a input-p TCP-I eth0-s 0/0 -- destination-port 21? J okay

Iptables-a input-p TCP-I eth0-s 0/0 -- destination-port 22? J okay

Iptables-a input-p TCP-I eth0-s 0/0 -- destination-port 80? J okay

Iptables-a input-p TCP-I eth0-s 0/0 -- destination-port 113? J okay

# UDP rules defining open UDP ports

Iptables-a input-p UDP-I eth0-s 0/0 -- destination-port 53? J ACCEPT

Iptables-a input-p UDP-I eth0-s 0/0 -- destination-port 2074? J ACCEPT

Iptables-a input-p UDP-I eth0-s 0/0 -- destination-port 4000? J ACCEPT

# ICMP rules

Iptables-a input-p ICMP-I eth0-s 0/0 -- destination-port 8? J ACCEPT

Iptables-a input-p ICMP-I eth0-s 0/0 -- destination-port 11? J ACCEPT

# FORWARD chain rules

# Accept the packets we want to forward

Iptables-a forward-I eth1-j ACCEPT

Iptables-a forward-m state -- state ESTABLISHED, RELATED-j ACCEPT

# OUTPUT chain rules

# Only output packets with local addresses (no spoofing)

Iptables-a output-p ALL-s 127.0.0.1-j ACCEPT

Iptables-a output-p ALL-s 10.0.0.1-j ACCEPT

Iptables-a output-p ALL-s 123.45.67.89-j ACCEPT

# IP spoofing of the POSTROUTING chain rules Gateway

Iptables-t nat? A postrouting? O eth0? J SNAT? To-source 123.45.67.89



(2) gateway IP disguise: static addresses use SNAT, dynamic addresses (dial-up) Use MASQUERADE

Example:

MASQUERADE must provide the interface Name (eth0, ppp0, etc.) to specify the path, as if the static address can also use MASQUERADE:

Iptables-t nat-a postrouting? O eth0? J MASQUERADE

SNAT must also specify the actual IP address as follows:

Iptables-t nat-a postrouting-o eth0-j SNAT -- to-source 12.12.12.12

(3) port forwarding

Example: redirect all Web services on the firewall computer (-d 15.15.15.15) to a computer on the LAN (10.0.0.25)

Iptables-t nat-a prerouting-p tcp-d 15.15.15.15? Dprot 80? J DNAT? To-destination 10.0.0.25



VII. IP Address type (range of the number in the first part)

Class A address: 0 ~ 127; the number of computers is 256*256*256. Subnet Mask 255.0.0.0.

Class B address: 128 ~ 191; the number of computers is 256*256. Subnet Mask 255.255.0.0.

Class C address: 192 ~ 233; supports 250 computers. 0 and 255 cannot be specified as host addresses. Subnet Mask 255.255.255.0.

Class C private IP address 192.168.0.0 ~ 192.168.255.255

8. ifconfig

Ifconfig: determines network connection conditions.

Ifconfig eth0 up: Start the eth0 interface.

9. Configure the NIC

The configuration file/etc/sysconfig/network-scripts/ifcfg-eth0 can be edited with vi. Example:

DEVICE = eth0 # DEVICE name, with the same name as the file.

ONBOOT = yes # Start the device when the system starts.

BOOTPROTO = static

IPADDR = 202.118.75.91 # IP address of this Nic

NETMASK = 255.255.255.0 # Subnet Mask

GATEWAY = 202.118.75.1 # gateway ip Address

MACADDR = 00: 02: 2D: 2E: 8C: A8 # mac address

10. FTP service

10.1 run the setup command to enable the vsftpd service process.

10.2 then modify the file/etc/xinetd. d/vsftpd. (However, vsftpd is attached to xinetd. d runtime 2 and 3)

(1) Change disable = yes to = no.

(2) configure the maximum number of connections for each client:

Add the following configuration statement to the configuration file/etc/xinetd. d/vsftpd:

Per_source = value. For example, per_source = 5 indicates that the maximum number of connections for each client is 5.

(3) configure the total number of concurrent connections on the server:

Add the following configuration statement to the configuration file/etc/xinetd. d/vsftpd:

Instances = value. For example, instances = 200 indicates that the total number of connections supported by the FTP server is 200.

(4) When vsftpd is run independently: it is very easy to configure an independent vsftpd. You only need to add the following configuration on the basis of the preceding main configuration file.

Set listen = YES: indicates that vsftpd is started independently.

Set max_clients = 200: indicates the total number of concurrent connections on the server.

Set max_per_ip = 4: specify the maximum number of connections for each client.





10.3 Configure/etc/vsftpd. conf (redhat9 is the/etc/vsftpd. conf file.



# Allow access by real users (users with accounts in the System)

Local_enable = YES

# Write permissions for real users

Write_enable = YES

# Set the mask of the uploaded files to 022. In this way, the permissions of uploaded files are 755 (rwxr-xr-x), that is, the file owner can read and write, the members of the same group can read and write,

# Other users in the system are readable and executable.

Local_umask = 022

# Anonymous user access is allowed. The anonymous user's account in the system is ftp

Anonymous_enable = YES

# Set the mask for files uploaded by anonymous users. In this way, the object upload permission is 777 (rwxrwxrwx), that is, all users can read and write the object.

Anon_umask = 000

# Anonymous users can upload and create directories. The three rows are valid only when write_enable = YES is set.

Anon_upload_enable = YES

Anon_mkdir_write_enable = YES

Anon_world_readable_only = NO

# Add the following code to grant anonymous users the permission to delete objects:

# Anon_other_write_enable = YES

# A specific prompt is displayed in each directory. These prompts are stored in the. message file in various directories.

Dirmessage_enable = YES

# When a user logs on to the ftp server, the following information is displayed no matter whether the logon is successful or not.

Ftpd_banner = Welcome to NiHao FTP service.

# Use logs to upload and download logs.

Xferlog_enable = YES

# Log File Location

# Xferlog_file =/var/log/vsftpd. log

# Use the standard fpd format for logs

Xferlog_std_format = YES

# The ftp service port is 20

Connect_from_port_20 = YES

# When users access the server through ftp, their login directory is used as the directory they see in ftp, which is called chroot.

# In this way, users cannot access contents other than their login directories, greatly enhancing security. The logon directory for anonymous users is/var/ftp/

Chroot_list_enable = YES

# The user in the/etc/vsftpd. chroot_list file is not chroot.

Chroot_list_file =/etc/vsftpd. chroot_list

# A maximum of five users can log on at the same time.

Max_clients = 5 # Some do not support this option. Just comment it out.

# Ftp service password verification module.

Pam_service_name = vsftpd

# Listen = YES # add this item (redhat9) if it runs independently ).

# Tcp_wrappers = YES # add this item (redhat9) if it runs independently ).



10.4 restart the xinetd service so that you can access your ftp server anonymously.

Next we will create an ftp Administrator Account

In the Linux ftp service, user permissions are restricted. First, permission restrictions for Linux file systems. The access permission for each file is expressed in rwxrwxrwx. Each user can only perform operations permitted throughout the county. Second, restrictions on ftp configuration. The operation permitted by the system. If the ftp configuration file is not permitted, the user still cannot perform this operation. For example, if the permission of a file is rwxrwxrwx, the system deems that anyone has the right to read and write the file. If anonymous users are not allowed to write data in vsftpd. conf, anonymous users still cannot modify this question.

The read permission on the directory file means that the file information in the directory can be read. Directory file write permission, which means you can create, delete, and rename files under this directory.

Run groupadd-r ftpAdmin to add an ftp Administrator group. -R indicates that this is a system group.

Run the useradd-c "ftp Administrator"-d/var/ftp/-G ftpAdmin-s/sbin/nologin-r ftpAdmin command to add an Administrator ftpAdmin. Where

-C "ftp Administrator" is the description of this user

-D/var/ftp/is the user's login directory

-G ftpAdmin is the user's group

-S/sbin/nologin is the shell used when the user logs on. This shell command is so weak that it cannot be accessed through telnet. That is to say, this administrator can only be a garbage cleaning worker. (Haha. Postmaster)

-R indicates that this is a system account and you do not need to create a login directory for it.

After the Administrator is created, give the incoming Directory management right to him.

Chown ftpAdmin/var/ftp/incoming: Set the directory owner to ftpAdmin.

Chmod 755/var/ftp/incoming: sets the directory permission to the owner for read/write execution. users in the same group can read and execute, and all users can read and execute.

In this way, our administrator can start management.

10.5 configure vsftpd to allow anonymous users to upload

// Modify the main configuration file/etc/vsftpd. conf of vsftpd

# Vi/etc/vsftpd. conf

// Delete the # Before the following two rows

// ① # Anon_upload_enable = YES allow anonymous users to upload

// ② # Anon_mkdir_write_enable = YES Enable write and Directory Creation permissions for anonymous users

// If you want the above two settings to take effect, you must also:

// (1) write_enable = YES

// (2) Anonymous Users have the write permission on the file system's upload directory

// Add the following configuration statement

// Anon_world_readable_only = NO

// The preceding configuration statement is used to open the browsing permission of anonymous users.

// Save the disk and exit vi after modification

//

// Create an anonymous upload directory

# Mkdir/var/ftp/incoming

# Modify upload Directory Permissions

# Chmod o + w/var/ftp/incoming/

#

// Restart xinetd

# Service xinetd restart



11. Web Services (httpd)

Select the httpd service in setup. The www Service does not require xinetd as its proxy process. The httpd process has been running in the system. The default www Service Directory is/var/www/html. You only need to put the home page in this directory to access it.

We can create a www administrator wwwAdmin by setting up an ftp administrator. Set the login directory to/var/www/html.

/Etc/init. d/httpd start # start the service

/Etc/init. d/httpd restart # restart

The configuration file is/etc/httpd/conf/httpd. conf.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.