如何在shell脚本中为用户分配密码


本文摘自PHP中文网,作者不言,侵删。

本篇文章给大家介绍的内容是关于如何在shell脚本中为用户分配密码,下面我们来看具体的内容。

我们先来看一下命令

1

echo <password> | passwd ?Cstdin <username>

例如:

使用以下命令更改shell脚本中用户jack的密码。例如,我们使用字符串password作为密码。

1

cho "password" | passwd --stdin user

分配用户输入密码:

使用以下命令从用户输入密码并分配给用户user。

1

2

read -p "Enter Password for User jack: " pwd

echo $pwd | passwd --stdin user

此外,我们还可以提示用户输入两次密码,以确认用户输入正确密码。使用以下命令从用户输入密码twic并分配给用户user。

1

2

3

4

5

6

7

8

9

10

11

12

while :

do

    read -p "Enter Password for User user: " pwd1

    read -p "Confirm Password for User user: " pwd2

    if [ "$pwd1" == "$pwd2" ]

    then

        break

    else

        echo "Password and Confirm password doesn't match...."

    fi

done

echo $pwd1 | passwd --stdin user

本篇文章到这里就已经全部结束了,更多其他精彩内容可以关注PHP中文网的Linux教程视频栏目!

以上就是如何在shell脚本中为用户分配密码的详细内容,更多文章请关注木庄网络博客

相关阅读 >>

详解shell实现ssh自动登陆

什么是posix shell

shell脚本应该怎么使用?

linux shell ftp按照日期去下载文件的方法

如何让shell访问正在运行的docker容器

freeworld.posterous.com linux bash shell cheat sheet----autho:raphael

linux终端执行shell脚本时提示权限不足

linux中shell脚本怎么运行

如何让shell访问正在运行的docker容器

shell基本语法的介绍与使用

更多相关阅读请进入《shell》频道 >>



打赏

取消

感谢您的支持,我会继续努力的!

扫码支持
扫码打赏,您说多少就多少

打开支付宝扫一扫,即可进行扫码打赏哦

分享从这里开始,精彩与您同在

评论

管理员已关闭评论功能...