Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

Basic knowledge points of Linux

2025-04-13 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >

Share

Shulou(Shulou.com)06/02 Report--

Understand Linux basics? This problem may be our daily study or work often see. I hope you learned something from this question. The following is the reference content brought to you by Xiaobian. Let's take a look together!

Common command alias

In one of the Linux Basics series, ls -l=ll was mentioned. This is an alias in Linux. Use alias to see the system default alias.

[root@hadoop001 ~]# alias alias cp='cp -i' alias egrep='egrep --color=auto' alias fgrep='fgrep --color=auto' alias grep='grep --color=auto' alias l.= 'ls -d .* --color=auto' alias ll='ls -l --color=auto' alias ls='ls --color=auto' alias mv='mv -i' alias rm='rm -i' alias which='alias | /usr/bin/which --tty-only --read-alias --show-dot --show-tilde'

The alias = command string will work in the current session. If you want it to work all the time, add the above command to the end of the environment variables file. See the next section for environment variables.

[root@hadoop001 ~]# alias ul='cd /usr/local' [root@hadoop001 ~]# alias alias cp='cp -i' alias egrep='egrep --color=auto' alias fgrep='fgrep --color=auto' alias grep='grep --color=auto' alias l.= 'ls -d .* --color=auto' alias ll='ls -l --color=auto' alias ls='ls --color=auto' alias mv='mv -i' alias rm='rm -i' alias ul='cd /usr/local' Add a user whose home directory is at/home/username

id username ==> Display user and user group information

[root@hadoop001 ~]# id dengdi uid=1001(dengdi) gid=1001(dengdi) groups=1001(dengdi) User ID Primary Group ID all groups

cat /etc/passwd==> Show all user information

dengdi(user name):x:1001(user id):1001(main group id)::/home/dengdi(home directory):/bin/bash(execution interpreter) If/bin/bash becomes/bin/false or/sbin/nologin, the user cannot log in.

userdel username ==> delete userdelete user, will delete/etc/passwd records; at the same time, if there are no other users in the group, delete the group but the home directory is still there, but the user and user group have changed

[root@hadoop001 ~]# ll /home/ total 0 drwx------. 3 centos centos 70 Jun 28 2017 centos drwx------ 2 1001 1001 59 Jun 17 23:48 dengdi

userdel and useradd

[root@hadoop001 ~]# userdel dengdi [root@hadoop001 ~]# useradd dengdi useradd: warning: the home directory already exists. Not copying any file from skel directory into it. Creating mailbox file: File exists

Let's see what the skel directory system prompts is. We ll -a /home/dengdi

[root@hadoop001 ~]# ll -a /home/dengdi/ total 12 drwx------ 2 dengdi dengdi 59 Jun 17 23:48 . drwxr-xr-x. 4 root root 32 Jun 17 23:48 .. -rw-r--r-- 1 dengdi dengdi 18 Apr 11 2018 .bash_logout -rw-r--r-- 1 dengdi dengdi 193 Apr 11 2018 .bash_profile -rw-r--r-- 1 dengdi dengdi 231 Apr 11 2018 .bashrc

skel directory is all the hidden files of.bash*, try to delete them and switch dengdi users

[root@hadoop001 ~]# ll -a /home/dengdi/ total 16 drwx------ 2 dengdi dengdi 79 Jun 18 00:06 . drwxr-xr-x. 4 root root 32 Jun 17 23:48 .. -rw------- 1 dengdi dengdi 5 Jun 18 00:06 .bash_history -rw-r--r-- 1 dengdi dengdi 18 Apr 11 2018 .bash_logout -rw-r--r-- 1 dengdi dengdi 193 Apr 11 2018 .bash_profile -rw-r--r-- 1 dengdi dengdi 231 Apr 11 2018 .bashrc [root@hadoop001 ~]# rm -rf /home/dengdi/.* rm: refusing to remove '. ' or '.. ' directory: skipping '/home/dengdi/. ' rm: refusing to remove '. ' or '.. ' directory: skipping '/home/dengdi/.. ' [root@hadoop001 ~]# ll -a /home/dengdi/ total 0 drwx------ 2 dengdi dengdi 6 Jun 18 00:08 . drwxr-xr-x. 4 root root 32 Jun 17 23:48 .. [root@hadoop001 ~]# su - dengdi Last login: Tue Jun 18 00:07:26 CST 2019 on pts/0 -bash-4.2$

So skel directory determines whether your [root@hadoop001 ~] or-bash-4.2 $6. groupadd user group ==> Add user group usermod -a -G user group dengdi==> Add user group new member dengdi usermod -g user group dengdi==> Modify xxx as main group

[root@hadoop001 ~]# groupadd bigdata [root@hadoop001 ~]# id ruoze uid=501(ruoze) gid=501(ruoze) groups=501(ruoze) [root@hadoop001 ~]# usermod -a -G bigdata ruoze [root@hadoop001 ~]# id ruoze uid=501(ruoze) gid=501(ruoze) groups=501(ruoze), 502(bigdata) [root@hadoop001 ~]# usermod -g bigdata ruoze [root@hadoop001 ~]# id ruoze uid=501(ruoze) gid=502 (bigdata) groups=502 (bigdata) After reassigning the primary group here, the original primary group will be lost

reassign user home directory

usermod -d path user or vi /etc/passwd

switch user

su ruoze The current path of switching users does not change, that is, the path before switching su - ruoze switches users and switches to the user's home directory, and the execution environment variable file takes effect.

passwd user ==> set password or reset password

Thank you for reading! After reading the above, do you know about Linux basics? I hope the content of this article is helpful to everyone. If you want to know more about related articles, please pay attention to the industry information channel.

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.

Share To

Servers

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report