[[email protected] ~]# cat /etc/redhat-release 版本号查询
CentOS release 6.6 (Final)
[[email protected] ~]# uname -r 内核查询
2.6.32-504.el6.x86_64
[[email protected] ~]# uname -m 32位还是64位
x86_64
[[email protected] ~]# hostname 主机名
wuyike 或:
[[email protected] ~]# uname -n 主机名
wuyike
建立一个新用户:
[[email protected] ~]# useradd keke
[[email protected] ~]# tail -1 /etc/passwd
keke:x:500:500::/home/keke:/bin/bash
[[email protected] ~]# tail -1 /etc/group
keke:x:500:
[[email protected] ~]# tail -1 /etc/shadow
keke:!!:17228:0:99999:7:::
给新用户设置密码:
[[email protected] ~]# passwd keke
查看当前用户:
[[email protected] ~]# whoami
root
[[email protected] ~]$ whoami
keke
提示符@的前面的字符代表当前用户(whoami),后面为主机名(hostname)
Linux命令提示符由PS1环境变量控制:
[[email protected] ~]# echo $PS1
[\[email protected]\h \W]\$
[[email protected] ~]# export PS1="[\[email protected]\h \W \t]\$"
[[email protected] ~ 20:56:05]$
其中PS1="[\[email protected]\h \W \t]\$" 可以通过全局变量配置/etc/profile文件调整。
su与su -
su:用户角色切换,但是环境变量不改变,还是上一个用户的环境变量
su -:用户角色和用户环境变量都切换
从普通用户到root需要输入root密码。从root到普通用户无需密码。
[[email protected] ~]$ env|grep keke
USER=keke
MAIL=/var/spool/mail/keke
PATH=/usr/local/bin:/bin:/usr/bin:/usr/local/sbin:/usr/sbin:/sbin:/home/keke/bin
PWD=/home/keke
HOME=/home/keke
LOGNAME=keke
[[email protected] ~]$ su
Password:
[[email protected] keke]# env|grep keke
USER=keke
PATH=/usr/local/bin:/bin:/usr/bin:/usr/local/sbin:/usr/sbin:/sbin:/home/keke/bin
MAIL=/var/spool/mail/keke
PWD=/home/keke
LOGNAME=keke
[[email protected] keke]# pwd
/home/keke
[[email protected] keke]# env|grep root
HOME=/root
[[email protected] keke]# exit
exit
[[email protected] ~]$ su -
Password:
[[email protected] ~]# env|grep keke
[[email protected] ~]# env|grep root
USER=root
MAIL=/var/spool/mail/root
PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin:/root/bin
PWD=/root
HOME=/root
LOGNAME=root