In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-03-09 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >
Share
Shulou(Shulou.com)06/03 Report--
Table of contents:
(1) sodu user handoff
(2) transfer files between Linux and Linux
(3) transfer files between Linux and Windows
(4) search for find files
(5) other search tools
(1) sodu user handoff
When we switch users in the system, we must know each other's password before we can switch, but very often the root password can not be known to everyone. To solve this problem, you can use the root user to set which users have permission to execute which commands, and the corresponding user uses the "sudo" command to switch users.
(1.2) We operate on the vms002 host, and we use the root user to open the / etc/sudoers configuration file, where the format of the configuration file can be seen in figure 1-2.
# gedit / etc/sudoers
Etc/sudoers file, we can edit it in the / etc/sudoers.d/ directory, while the / etc/sudoers configuration file will take the files in the / etc/sudoers.d/ directory as part of itself (figure 1-3), indicating that when jerry users execute mount and umount commands on the vms002.example.com host, they will execute according to the permissions of the root user (figure 1-4).
# gedit / etc/sudoers.d/jerry
(1.4) at this time, we found that we could not execute the jerry mount command using jerry before creating the / etc/sudoers.d/jerry file, and then we edited the / etc/sudoers.d/jerry file to allow jerry users to execute mount and umount commands. At this time, we logged in and switched to the jerry user. Use the sudo command to find that you can normally use the mount mount command (figure 1-5). Note: when we use the jerry user to execute the sudo command, we need to execute the jerry user's password once. The system saves the password for 5 minutes by default. If we need to clear the saved password, we can use the "sudo-k" command (figure 1-6).
# sudo mount / dev/cdrom / mnt/
# sudo-KMMI-clear the password saved by the system
# sudo-LMMI-lists all permission information allowed to execute in the system
(1.5) if we want jerry users not to execute passwords when executing mount or umount commands, we can add the "NOPASSWD" parameter, which means that when jerry users execute mount and umount commands on vms002.example.com hosts, they will execute the commands according to the privileges of root users, and there is no need to enter password information (figure 1-8). When we execute at this point, we will find that the jerry user directly executes the mount command, and the mount is successful (figure 1-9).
(1.6) if we want jerry users to be able to execute all commands according to the permissions of root users, we can use the "ALL" parameter to indicate that all commands are executed according to the permissions of root users (figure 1-10). At this time, we can use the "sudo-I" command to switch to the administrator root and execute all commands (figure 1-11).
# sudo-iMurray-switch to administrator permissions
(1.7) generally, we can use sudo and network users together. For example, we have a directory service host that stores account information, and there are several member servers. After the network user's service is set up, for example, now we have a tom network user. In general, we can log in to the system using the tom network user name from any member server. Now we set in the configuration file of sudo, the relevant permissions that can be executed by tom users when logging in on vms001 hosts, and there are no permissions when using tom users to log in on other member server hosts, so that permissions can be well managed.
(2) transfer files between Linux and Linux
(2.1) in the system sometimes we need to transfer some small files or some fragmentary files, then we need some transfer tools for file transfer, usually there are two main tools for transferring files between Linux system and Linux system, scp and rsync, both of which are based on ssh services.
(2.2) how to use scp
(2.2.1) first let's learn about the scp tool. The syntax of the scp tool is as follows: "scp-option / path2/file remoteIP:/path3", which means to copy the files in the directory under the current host to the directory under the remote host.
(2.2.2) We try to copy the hosts file on the vms001 host to the / opt/ directory of the vms002 host. We can do the following and find that the file copy of the vms001 host can be transferred to the vms002 host normally (figure 2-3).
# scp / etc/hosts vms002:/opt/
(2.2.3) then we switched to the tom user on the vms001 host, and then we also tried to copy the / etc/hosts file to the / opt/ directory of the vms002 host. We found that we could not copy and transfer the file successfully, because we did not specify a user name on the vms001 host, so the current user name tom transfer file (figure 2-4) was used by default at this time to query the permission information of the / opt/ directory. We found that other users in the directory did not have writeable permissions, so we could not copy and transfer the files successfully (figure 2-5). When we specify the use of root users to transfer to the / opt directory of the vms002 host (figure 2-6), we find that the hosts file can be viewed normally in the / opt directory of the vms002 host (figure 2-7).
# useradd tom--- create a tom user
# echo redhat | passwd-- stdin tom--- creates a password for tom users
# ls-ld / opt/--- permission to view the opt directory
(2.2.4) then we first generate a key pair on the vms001 host without entering a password (figure 2-8), and then copy the public key pair from the vms001 host to the vms002 host. At this time, we find that the vms001 host can connect directly to the vms002 host without entering the password (figure 2-9). At the same time, when we transfer the / etc/hosts file from the vms001 host to the vms002 host It is also possible to transmit successfully without entering a password (figure 2-10).
# ls .ssh /
# ssh-keygen-N "- generate a key pair that does not require a password
# ssh-copy-id vms002--- copies public key pairs from the vms001 host to the vms002 host
# scp / etc/hosts vms002:/opt/--- copy the files of vms001 host to vms002 host
(2.2.5) now our requirement is to copy the files under the / boot directory of the current vms001 host to the / opt directory of the vms002 host. At this time, we can copy the files in the directory using scp-r recursion (figure 2-11). At this time, we can see that a boot directory has been generated under the / opt directory on the vms002 host (figure 2-12).
# scp-r / boot/ vms002:/opt/
(2.2.6) We can also do it the other way around, that is, we can copy the files of the remote host to the local. For example, we copy the vms002.txt file on the vms002 host to the vms001 host, and we find that the vms002.txt file can be seen on the vms001 host.
# scp vms002:~/vms002.txt.-copy the files on the vms002 host locally
(2.3) how to use rsync
(2.3.1) the rsync command is a remote data synchronization tool that allows you to quickly synchronize files between multiple hosts through LAN/WAN. Rsync uses the so-called "rsync algorithm" to synchronize files between local and remote hosts. This algorithm transfers only different parts of the two files, rather than the whole file each time, so it is quite fast. The syntax of rsync is "rsync-option / path2/file remoteIP:/path3", which means to copy the files of the current host to the directory of the remote host.
(2.3.2) when we tried to copy the / etc/hosts file to the / opt directory of the vms002 host, we found that the hosts file on the vms001 host already existed on the vms002 host (figure 2-16).
# rsync / etc/hosts vms002:/opt/--- copy the / etc/hosts file to the / opt directory of the vms002 host
(2.3.3) if we want to copy all the files in the / boot/ directory of the vms001 host to the / opt directory of the vms002 host, we can use the rsync-r command (figure 2-17). Note that here we use "/ boot/" to represent all the files in the boot directory. At this point, we found that all the files in the boot directory already exist in the / opt directory on the vms002 host (figure 2-18).
# rsync-r / boot/ vms002:/opt/--- copies all the files in the / boot/ directory to the / opt directory of the vms002 host
(2.3.4) if we want to copy the / boot/ directory and all the files under the / boot/ directory of the vms001 host to the / opt directory of the vms002 host (figure 2-19), note that we use "/ boot" here to copy the directory and the files under the directory as a whole. At this time, it is found that a boot directory has been generated under the / opt directory on the vms002 host. And there are all the files transferred by vms001 in the boot directory (figure 2-20).
# rsync-r / boot vms002:/opt/
(2.3.5) if we want to uniformly copy and transfer all the information of the file, such as time, owner, group, and so on, we can use the rsync-a command to achieve this requirement.
# rsync-a / boot vms002:/opt/
(2.3.6) sometimes in order to make better use of rsync services, we can also use the graphical interface tool grsync, the common version of grsync is the grsync-1.2.4-3.el7.nux.x86_64.rpm package.
(3) transfer files between Linux and Windows
(3.1) how to use lrzsz
(3.1.1) for file transfer between Linux and Windows systems, we usually have many small tools to use, such as our common lrzsz, we first have to make sure that lrzsz has been installed on the server, if we are using a graphical interface installation, then lrzsz is already installed by default; if we are using a minimized installation of the system, there is no default installation of lrzsz tools.
(3.1.2) We can enter the rz command on the vms001 host so that the files on the Windows host can be transferred to the Linux system.
(3.1.3) if we want to transfer files from the Linux system to the Windows host, we can use the sz command on the vms001 host to achieve this requirement.
# sz vms002.txt
(3.1.4) what we need to know is that the lrzsz tool can connect to the server through xshell, secureCRT and other tools, but if we are using a putty client, it is not supported to use the lrzsz tool.
Generally speaking, the lrzsz we use above is convenient for transferring small files. If we want to transfer large files, we generally do not recommend using lrzsz. At this point, we can use the tools provided by the xshell client, we can click "New File transfer" or use the shortcut key "Ctrl+Alt+F" to open the tool, then we can transfer large files at a very fast rate.
Sometimes we can also use other tools to achieve file transfer between Linux and Windows systems, such as WinSCP or FileZilla, can also achieve our needs.
(4) search for find files
(4.1) generally, we use the find command to find files. The format of the find command is "find directory-attribute value". If no directory is specified, the query is performed under the current directory by default. The attributes mainly include: name, iname, user, group, nouser, nogroup, uid, gid, size, mtime, mmin, type, perm
Then we create a rh224 directory on the vms002 host, then create the related files, and set the corresponding owner and group information to the created files.
# chown jerry aa--- changed the owner of aa to jerry
# chown jerry.jerry bb--- changed the owner and group of bb to jerry
# chown .users cc--- changed the subordinate group of cc to users
# chown 101.users dd--- changes the ownership of dd to 101genera and groups to users
# chown. 103 ee--- modified the subordinate group of ee to 103
(4.3) if we want to find a file named lwang in the system, we can use the "- name" parameter; if we want to ignore case when querying names, we can use the "- iname" parameter.
# find /-name lwang--- finds a file named lwang, and you can use the "- name" parameter
# find /-iname lwang--- ignores case when querying names, and the "- iname" parameter can be used.
(4.4) if we want to query files owned by jerry users, we can use the "- user" parameter; if we want to query files with a group of jerry, we can use the "- group" parameter query.
# find-user jerry--- queries files owned by jerry users
# find-group jerry--- queries files belonging to jerry users
(4.5) because the uid of jerry users is 1000, if we want to query a file with a uid of 1000, we can use the "- uid" parameter; if we want to query a file with a gid of 1000, we can use the "- gid parameter"
# find-uid 1000 Murray-query files with a uid of 1000
# find-gid 1000 Murray-query files with a gid of 1000
(4.6) if you want to query a file that does not have a master, you can use the "- nouser" parameter; if you want to query a file that does not have a group, you can use the "- nogroup" parameter.
# find-nouser--- query does not have a master file
# find-nogroup--- query files that do not belong to the group
(4.7) if we want to query files in which both the owner and the group are jerry users, we can use the "- a" parameter to connect, indicating that both conditions should be met at the same time; and if we want to query files in which the owner is jerry or the group is jerry users, we can use the "- o" parameter to indicate that all conditions are met as long as one of them is met.
# find-user jerry- a-group jerry--- queries files where both the owner and the group are jerry users
# find-user jerry- o-group jerry--- queries files for which the owner is jerry or the group is jerry user
Then we re-create the following seven files on the vms002 host, if we want to query files whose size is exactly equal to 3M, then we can directly use "3M", if we want to query all files larger than 3M, we can use the "+ 3M" parameter, at this time we can query according to the file size size.
# rm-rf [amerz] *-delete all files in the rh224 directory
# dd if=/dev/zero of=file1 bs=1M count=1--- create a 1m file file1
# find-size 3M murmura-query files with exactly 3m file size
# find-size + 3M murmuri-query all files whose file size is larger than 3m
# find-size + 3M-o-size 3M Murray-query all files whose file size is greater than or equal to 3m
(4.9) We can also query according to the time attribute of the file, we can query the file created with an interval of 1 day, the file created with an interval of more than 1 day, and the file created with an interval of less than 1 day.
# find-mtime 1Murray-query the created files with an interval of 1 day
# find-mtime + 1Murray-query the created files with an interval of more than 1 day
# find-mtime-1 the time interval of query created files is less than 1 day
(4.10) We can also query the creation time status of files with a precision of minutes through the mmin parameter.
# find-mmin 44muri-query file creation time is 44 minutes
# find-mmin-44murmuri-query files that take less than 44 minutes to create
# find-mmin + 44murmuri-query files that take more than 44 minutes to create
We can also query by the file type type, we first create a directory rh224 in the system, and then create a soft connection from the file6 file connection to the lwang file (figure 4-15). We know that when querying file attributes, the "d" parameter represents a directory file, "-" represents a normal file, "l" represents a soft connection, "b" represents a block device and block file, and "c" represents a character device. If we want to query a file of a block device type, we can use the "- b" parameter, and if we want to query a normal type of file device, we can use the "- f" parameter (figure 4-16).
# ln-s lwang file6--- creates a soft connection, and file6 connects to the lwang file
# find-type BMMI-query files of block device types
# find-type fmuri-query devices of common file types
(4.12) We can also query through permissions perm, for example, we now design a permission ugo=364 (figure 4-17), and we set the permissions of the file1 file to 364, and then we query all files under the current directory whose permissions are fully in line with the settings of 364. At this time, we find that only file1 files meet the permission requirements (figure 4-18).
# chmod 364file1--- allows 364 permissions to modify file files
# find-perm 364-query all files in the current directory whose permissions are in full compliance with the 364 settings
# find-perm + 364
We select all the files with permissions of at least 364, so we find that file1, file2 and file6 meet the requirements.
# find-perm-364Murray-query permissions can be more than 364permissions, but not less
(4.14) We can use / 364 to indicate that as long as any of the three permissions of the ugo of the file is contained in one of the three locations of the 364 that we queried, then the file meets the requirements. At this point, we found that except for the permissions of lwang, other files are in line with the requirements.
# chmod 200file3--- set the file3 file to 200,
# chmod 004 file4--- sets the file4 file to 004
# chmod 020 file5--- sets the file5 file to 020
# chmod 411 lwang--- sets the lwang file to 411
# find-perm / 364 Murray-query files for which the permissions of any of the three permissions in ugo are contained in one of the three locations we have queried
(4.15) if we want to query the attributes of the corresponding file, we can use the xargs command to pass the queried file at the beginning of file to the ls command through the xargs parameter, and then we can view the attribute information of the found file (figure 4-21). We can also use the xargs parameter to perform the delete operation (figure 4-21-1).
# find-name "file*" | xargs ls-Lmuri-query the attributes of all files at the beginning of file
# touch file {1... 10}-create 10 files starting with file
# find-name "file*" | xargs rm-rf--- deletes all files beginning with file
(4.16) in the second way, we can also use the "- exec" command to view the attribute information of the queried file, and delete all the files at the beginning of the queried file by using "- exec".
# find-name "file*"-exec rm-rf {}\;-delete all files at the beginning of the queried file
(4.17) if we have a directory besides files in our current directory, and the directory also contains subfolders, then when we execute the "# find-name lwang" command, we will automatically do a recursive query in the subfolder. If we do not want to do a deep query now, but only want to do a layer-1 query, we can use "# man find" to query, and then look for the "maxdepth" keyword. Recursive search
# find-maxdepth 1-name lwang--- looks for a file named lwang on the first level of the current directory
(5) other search tools
(5.1) in the Linux system, we have other commonly used tools for query operations, such as the which command. If we want to query the specific path under which the date command is executed, we can use "# which date" to query.
# which date--- query which path is the date command in
# which vim
# which ifconfig
(5.2) We can also use the locate command, for example, if we want to query all the file information about the ceph keyword in the system, we can use the "# locate ceph" command, where we can query all the file information about the ceph keyword in the system (figure 5-2). But if we temporarily create a file ceph.txt in the system, we find that we cannot find the newly created file (figure 5-3). This is because the locate command uses the information in a database when querying, and the database is updated once a week or so, so we can't find any information when we search for the file we just created. All we need to do at this point is to update the database, and we find that we can search for the ceph.txt file in the root directory we just created (figure 5-4).
# locate ceph--- queries all file information about the ceph keyword in the system
# updatedb--- updates the database
Sometimes when we use the locate command, it is easy to be confused with the locale command because they look so much like twins. The locale command is used to set the default encoding for our system. When we log in using ssh in xshell, the system code is UTF-8, so we must ensure that the ssh client code is consistent with the system code, otherwise there will be garbled problems.
(5.4) for example, when we open a browser, the current system defaults to "LANG=zh_CN.UTF-8", that is, Chinese, but we want to open it in American English, so we can use the LANG command to specify the American English code before executing the firefox command (figure 5-7). If we want to change the default encoding of the system, we should do so in the / etc/locale.conf configuration file (figure 5-8).
Note: on RHEL 6 systems, the default encoding of the system is configured in the / etc/sysconfig/i18n file.
# LANG=en-us firefox &-Open the browser in American English
# cat / etc/locale.conf
-this is the end of this article. Thank you for reading-
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.