根据UID复制用户的脚本

发布于 2024-08-31 22:10:28 字数 382 浏览 2 评论 0原文

我正在寻找一种将所有非系统用户从一台电脑复制到另一台电脑的方法。我可以使用此方法复制组和 passwd 文件

awk -F":" ' $3 > 499 ' etc/passwd >> /etc/passwd
awk -F":" ' $3 > 499 ' etc/group >> /etc/group

但是,由于它不存储 UID,我该如何复制影子文件呢?假设有超过 1000 个用户,因此使用用户名执行 grep,例如 egrep '(bob|bill|sarah|sal):' etc/shadow >>> /etc/shadow 从上面的 awk 代码生成用户名,效率有点低,但这是一个可能的选择。

I'm looking for a way to copy all non-system users from one PC to another. I can get the group and passwd files copied over using this

awk -F":" ' $3 > 499 ' etc/passwd >> /etc/passwd
awk -F":" ' $3 > 499 ' etc/group >> /etc/group

But, how would I go about getting the shadow file copied over since it does not store the UID? Assume that there are over 1000 users, so doing a grep with the usernames, such as egrep '(bob|bill|sarah|sal):' etc/shadow >> /etc/shadow generating the usernames from the awk code above, would be a bit inefficient, but a possible option.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

仲春光 2024-09-07 22:10:28

awk -F":" ' $3 >第499章sudo grep -f - /etc/shadow > Shadow.out

如果用户名是其他用户名的一部分,则先前的答案可能会为每个用户生成多行

awk -F":" ' $3 > 499 {print "^"$1":"} ' /etc/passwd | sudo grep -f - /etc/shadow > shadow.out

Previous answer could produce multiple lines per user if username is part of other usernames

我一向站在原地 2024-09-07 22:10:28
awk -F":" ' $3 > 499 {print $1} ' /etc/passwd | sudo grep -f - /etc/shadow > shadow.out
awk -F":" ' $3 > 499 {print $1} ' /etc/passwd | sudo grep -f - /etc/shadow > shadow.out
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文