使用 crypt 密码生成的 Useradd
我正在编写一个我认为非常简单的脚本,用于使用“useradd”动态创建 FTP 用户。这个过程的几个部分我不熟悉,而且一整天的研究并没有让我走得太远。 这是我所拥有的:
password="pass"
pass=$(perl -e 'print crypt($ARGV[0], "wtf")' $password)
useradd -d HOME_DIR -s /bin/bash -g GROUP -p $pass -f -1 testing
注释
- HOME_DIR 和 GROUP 是占位符
- 我对“useradd”的 home/base_dir(-d、-b)或组(-g)功能没有任何问题
主题:
- 为什么我的密码生成工作不起作用?
- /bin/bash 是纯 FTP 用户使用的正确 shell,还是我会使用 /bin/false 或其他 shell?
- 默认情况下,useradd 会禁用帐户,直到他们提供自己的密码为止,我该如何绕过此操作?
- 我不想使用 passwd 实用程序,因为它会削弱我自动生成 FTP 帐户的能力,我找到了解决方案 这里,但我不明白解决方案
如果我的做法是错误的,或者我想做的事情是否不可能,或者如果我对本文中所陈述的任何内容都存在误解。 感谢您提供任何帮助。 :D
I am working on what I thought was a very simple script to dynamically create an FTP user using 'useradd' There are several parts of this process I am unfamiliar with, and an entire day's research has not gotten me too far. Here is what I have:
password="pass"
pass=$(perl -e 'print crypt($ARGV[0], "wtf")' $password)
useradd -d HOME_DIR -s /bin/bash -g GROUP -p $pass -f -1 testing
Notes
- HOME_DIR and GROUP are placeholders
- I am not having issues with the home/base_dir (-d, -b) or group (-g) functionality of 'useradd'
Topics:
- Why are my password generation efforts not working?
- is /bin/bash the correct shell to use for a purely FTP user, or would I use /bin/false or a different shell?
- By default, useradd disables an account until they provide their own password, how do I bypass this?
- I do not want to use the passwd utility as it cripples my ability to automagically generate FTP accounts, I found a solution to this here, but I do not understand the solution
Let me know if I am going about this all wrong, or if what I am trying to do is not possible or if I am misinformed about anything I have stated herein. Thank you for any help you can provide. :D
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
关于密码生成:
根据您的系统,可能还存在 Blowfish 或 SHA-2 系列
crypt
,并且出于安全原因可能会禁用传统 DES。 PAM 也可以在这里添加自己的复杂性。话虽如此,它
在我的系统上运行得很好。
关于 shell:
/sbin/nologin
对于无法登录的用户来说是传统的。 您必须仔细检查 FTP 守护程序的配置,看看是否将它们排除在 FTP 访问之外。关于禁用帐户:
如上所示,如果给出工作密码,这对我来说是有效的,正如预期的那样。
关于其他解决方案:
您对替代解决方案有什么不了解的地方? 我觉得很清楚。
只需将“
username:password
”通过管道传输到“chpasswd
”即可。如果您想要仅限 FTP 的用户,我建议使用支持虚拟用户的 FTP 守护进程,例如 glftpd、纯 FTPd, ProFTPD,vsftpd,...实际上似乎所有常见的都是如此。 这样,FTP 帐户不需要真实的系统帐户。
Regarding password generation:
Depending on your system, there may also be Blowfish or SHA-2 family
crypt
s as well, and it's possible that the traditional DES may be disabled for security. PAM can add its own complications in here too.That being said, the
works just fine on my system.
Regarding the shell:
/sbin/nologin
is traditional for login-disabled users. You'll have to double-check your FTP daemon's configuration to see if that excludes them from FTP access.Regarding the disabled account:
As seen above, works for me, as expected if given a working password.
About the other solution:
What don't you understand about the alternate solution? It seems very clear to me.
Just pipe "
username:password
" into "chpasswd
".If you want FTP-only users, I would recommend using a FTP daemon that supports virtual users like glftpd, Pure-FTPd, ProFTPD, vsftpd, ... actually it seems that all the common ones do. This way, an FTP account does not require a real system account.
如果您想创建“仅 FTP”用户,您应该查看 rssh
为您的发行版安装 rssh,并将“仅限 FTP”用户的 shell 设置为“/usr/bin/rssh”
效果很好
If you want to create "FTP only" users, you should look at rssh
Install rssh for your distro, and set the shell for the "FTP only" user to "/usr/bin/rssh"
Works very well