请问一下shell的问题
Tofloor
poster avatar
chatop
deepin
2016-05-28 05:51
Author
本帖最后由 chatop 于 2016-5-28 00:54 编辑

请教一下,
如何 能使用shell脚本建立一个用户,并指定用户密码
同时要求这个用户有自己的家目录,而且拥有sudo权限
如何在shell脚本中自动完成

这两天一直在搞这个问题,实在搞不定了,来问问,麻烦了解的帮一下忙

谢谢

Reply Favorite View the author
All Replies
avatar
boner_killer
deepin
2016-05-28 06:10
#1
没明白你说的什么
Reply View the author
avatar
136******54
deepin
2016-05-28 06:11
#2
新建用户并自动建立家目录:useradd -m newuser
设定新用户密码:passwd newuser
第二个命令是交互的,我不知道怎么在脚本里自动指定
Reply View the author
avatar
Feng Yu
deepin
2016-05-28 06:27
#3
实在太容易了,useradd支持非交互
Reply View the author
avatar
呆了个呆
deepin
2016-05-28 06:42
#4
你这个没难度,我想知道如何在shell中新建一个可以在deepin登陆器中登陆的用户,之前直接修改passwd和group文件修改了桌面用户的用户名和组名,结果桌面就进不去了,后来是用passwd命令新设了密码才进去的,直接用adduser或useradd添加的用户在登陆器用看不见,我想知道这个怎么用命令添加
Reply View the author
avatar
chatop
deepin
2016-05-28 08:20
#5
大家都想简单了,在不使用except的情况下,,目前我还没有发现任何 一种 办法 能成功的实现脚本建立用户
但有一种方法 虽然可以实现脚本建立,但只适合单一任务 的,做为多元化任务 的脚本来讲又不适用

有一个办法
useradd -m username
passwd username < password
password
EOF

这样是可以的,,但这个脚本因为遇到EOF而结束了,后续脚本不会再跑了,
单独把这段代码独立出来文件的话不知道行不行,还没有测试过。。

但是总觉得 这样的方法是不规范的,,希望 能有更好的办法 。
Reply View the author
avatar
chatop
deepin
2016-05-28 08:23
#6
这估计都成为debian系的老大难问题了,,,我脚本到不是在deepin上跑,是跑在linuxmint for debian上的
Reply View the author
avatar
hwang
deepin
2016-05-28 09:27
#7
https://bbs.deepin.org/post/39765
这估计都成为debian系的老大难问题了,,,我脚本到不是在deepin上跑,是跑在linuxmint for debian上的
...

无意冒犯,我觉得这真的挺简单的,因为最近在学shell脚本所以看到这个就写写
#!/bin/bash
useradd -m username
echo "fedora" | passwd --stdin username
echo "username   ALL=(ALL)         ALL" >>/etc/sudoers
Reply View the author
avatar
chatop
deepin
2016-05-28 18:36
#8
Debian的passwd是没有--stdin参数的
Reply View the author
avatar
hwang
deepin
2016-05-28 19:11
#9
https://bbs.deepin.org/post/39765
Debian的passwd是没有--stdin参数的

哦,不好意思,我一直用redhat系的fedora和centos,真不知道这也是个问题,不过在ubuntu论坛看到一个替代的方法echo 'username:password' | chpasswd,你看看行不行
Reply View the author
avatar
chatop
deepin
2016-05-29 10:21
#10
本帖最后由 chatop 于 2016-5-29 02:25 编辑
https://bbs.deepin.org/post/39765
哦,不好意思,我一直用redhat系的fedora和centos,真不知道这也是个问题,不过在ubuntu论坛看到一个替代 ...

谢谢你,

  1. useradd -m autoupdater  
  2. echo 'autoupdater:autoupdater123' | chpasswd
  3. echo "autoupdater  ALL=(ALL:ALL)  ALL" >>/etc/sudoers
Copy the Code



这个方法是可行的,测试通过
另外,debian下--stdin 虽然不支持,但是有-S 支持,效果是一样的。

Reply View the author