redhat修改root密码命令(redhat 修改用户密码)

redhat修改root密码命令(redhat 修改用户密码)nbsp 一 修改用户密码的几种方式 1 passwd nbsp root nbsp 用户名 nbsp 正常情况 通过 2 次输入新密码的方式修改用户密码 输入密码不可见 root linuxprobe passwd nbsp root Changing password for user root New password BAD PASSWORD The password is shorter than 8 characters Retype new



 一、修改用户密码的几种方式

1. passwd  root  用户名 

正常情况,通过2次输入新密码的方式修改用户密码,输入密码不可见。

[root@linuxprobe ~]# passwd  root

Changing password for user root.

New password:

BAD PASSWORD: The password is shorter than 8 characters

Retype new password:

passwd: all authentication tokens updated successfully.

 

2. passwd  --stdin  用户名

--stdin此选项用于指示passwd应从标准输入(可以是管道)读取新密码,新密码可见,只需输入一次。

 

[root@linuxprobe ~]# passwd  --stdin root

Changing password for user root.

newpassword

passwd: all authentication tokens updated successfully.

 

3. echo “新密码”|passwd --stdin 用户名

[root@linuxprobe ~]# echo newpassword | passwd --stdin root

Changing password for user root.

passwd: all authentication tokens updated successfully.

 

这种操作方式较为简单,但是其它用户可以通过history命令可以查到用户执行的命令,有一定的安全隐患。

 

二、管道符号 |

ls -l | more  

三、重定向

命令 > 文件:将标准输出重定向到一个文件中(清空原有文件的数据)
命令 2> 文件:将错误输出重定向到一个文件中(清空原有文件的数据)
命令 >> 文件:将标准输出重定向到一个文件中(追加到原有内容的后面)
命令 2>> 文件:将错误输出重定向到一个文件中(追加到原有内容的后面)
命令 &>> 文件:将标准输出与错误输出共同写入到文件中(追加到原有内容的后面)



 

四、环境变量

 

五、转义字符
最常用的4 个转义字符如下:

#定义变量P为5
[root@linuxprobe ~]# P=5
#输出变量P
[root@linuxprobe ~]# echo $P
5



1)单引号(''):转义其中所有的变量为单纯的字符串。
[root@linuxprobe ~]# echo 'P=$P'
P=$P

2)双引号(""):保留其中的变量属性,不进行转义处理。


3)反斜杠():使反斜杠后面的一个变量变为单纯的字符串。

[root@linuxprobe ~]# echo "P=$$P"
P=13412P
[root@linuxprobe ~]# echo "P=$$P"
P=$5


4)反引号(``):把其中的命令执行后返回结果。
[root@linuxprobe ~]# echo `echo $P`
5
结果完全等同于
[root@linuxprobe ~]# echo $P
5
当然我们可以执行其它语句[root@linuxprobe ~]# echo `ls -l`
total 24 -rw-------. 1 root root 1032 Feb 17 16:54 anaconda-ks.cfg drwxr-xr-x. 2 root root 6 Feb 18 15:44 Desktop drwxr-xr-x. 2 root root 6 Feb 18 15:44 Documents drwxr-xr-x. 2 root root 6 Feb 18 15:44 Downloads -rw-r--r--. 1 root root 192 Feb 24 15:51 examWhile.sh -rw-r--r--. 1 root root 319 Feb 24 15:59 guess.sh -rw-r--r--. 1 root root 1083 Feb 18 15:40 initial-setup-ks.cfg drwxr-xr-x. 2 root root 6 Feb 18 15:44 Music drwxr-xr-x. 2 root root 6 Feb 18 15:44 Pictures drwxr-xr-x. 2 root root 6 Feb 18 15:44 Public -rw-r--r--. 1 root root 81 Feb 24 11:41 rand100.sh drwxr-xr-x. 2 root root 6 Feb 18 15:44 Templates -rw-r--r--. 1 root root 2690 Feb 18 15:55 test.txt drwxr-xr-x. 2 root root 6 Feb 18 15:44 Videos
[root@linuxprobe ~]# ls -l
total 24
-rw-------. 1 root root 1032 Feb 17 16:54 anaconda-ks.cfg
drwxr-xr-x. 2 root root    6 Feb 18 15:44 Desktop
drwxr-xr-x. 2 root root    6 Feb 18 15:44 Documents
drwxr-xr-x. 2 root root    6 Feb 18 15:44 Downloads
-rw-r--r--. 1 root root  192 Feb 24 15:51 examWhile.sh
-rw-r--r--. 1 root root  319 Feb 24 15:59 guess.sh
-rw-r--r--. 1 root root 1083 Feb 18 15:40 initial-setup-ks.cfg
drwxr-xr-x. 2 root root    6 Feb 18 15:44 Music
drwxr-xr-x. 2 root root    6 Feb 18 15:44 Pictures
drwxr-xr-x. 2 root root    6 Feb 18 15:44 Public
-rw-r--r--. 1 root root   81 Feb 24 11:41 rand100.sh
drwxr-xr-x. 2 root root    6 Feb 18 15:44 Templates
-rw-r--r--. 1 root root 2690 Feb 18 15:55 test.txt
drwxr-xr-x. 2 root root    6 Feb 18 15:44 Videos






















 

总结:双引号、单引号,反引号

反引号最傻,给啥鸡毛都当令箭,给啥串都当命令去执行

单引号一般傻,给啥出啥,不管给的东东里面有没有变量

双引号最聪明,总会试着去判断一下所给的东东里有没有变量,如果有,则输出变量名

今天的文章 redhat修改root密码命令(redhat 修改用户密码)分享到此就结束了,感谢您的阅读。
编程小号
上一篇 2026-03-12 23:33
下一篇 2025-02-10 22:06

相关推荐

版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 举报,一经查实,本站将立刻删除。
如需转载请保留出处:https://bianchenghao.cn/bian-cheng-ri-ji/53226.html