
useradd
CLI에서 명령을 사용하는 동안 새 사용자에 대해 암호화된 로그인 비밀번호를 생성하고 싶습니다 . 옵션을 사용하면 -p
비밀번호를 생성할 수 있다는 것을 알고 있지만 이 옵션을 사용해도 비밀번호가 암호화되지는 않습니다. passwd [username]
를 통해 새로운 사용자를 생성한 후 별도로 명령어를 이용하여 암호화된 비밀번호를 생성할 수 있다는 것도 알고 있는데 useradd
, 말씀드린 것처럼 명령어를 통해 암호화된 비밀번호를 생성하는 방법을 알고 싶습니다 useradd
.
답변1
Perl을 사용할 수 있습니다.
perl -e "print crypt(\"foo\", \"\$6\$$(</dev/urandom tr -dc 'a-zA-Z0-9' | head -c 32)\$\")"
또는 모듈이 있는 Python crypt
:
python -c "import crypt; print crypt.crypt(\"foo\", \"\$6\$$(</dev/urandom tr -dc 'a-zA-Z0-9' | head -c 32)\$\")"
foo
: 암호화할 비밀번호$6
: 암호화 유형(이 경우 SHA-512)$(</dev/urandom tr -dc 'a-zA-Z0-9' | head -c 32)
: 암호화 솔트, 이 경우 임의의 32자 문자열입니다.
다음과 함께 useradd
:
useradd [...] -p"$(perl -e "print crypt(\"foo\", \"\$6\$$(</dev/urandom tr -dc 'a-zA-Z0-9' | head -c 32)\$\")")" [...]
또는:
useradd [...] -p"$(python -c "import crypt; print crypt.crypt(\"foo\", \"\$6\$$(</dev/urandom tr -dc 'a-zA-Z0-9' | head -c 32)\$\")")" [...]
답변2
passwd --expire
사용자 ID를 생성한 다음 이를 사용하면 관리자가 생성한 비밀번호 사용자 관리의 번거로움을 모두 건너뛸 수 있습니다 . 에서 man passwd
:
-e, --expire
Immediately expire an account's password. This in effect can force
a user to change his/her password at the user's next login.
답변3
passwd는 Ubuntu에서 --stdin을 지원하지 않으므로 다음을 시도해 볼 수 있습니다.
perl -e "print crypt('password','sa');"
보다https://administratosphere.wordpress.com/2011/06/16/geneating-passwords-using-crypt3/
답변4
다음은 Ubuntu 18.04 LTS에서 나에게 효과적이었습니다.
echo 'your_password' > /tmp/pw.txt
pw="$(makepasswd --crypt-md5 --clearfrom=/tmp/pw.txt)"
sudo useradd -p "${pw}" your_username
rm -f /tmp/pw.txt
먼저 다음을 makepasswd
사용하여 설치해야 할 수도 있습니다.(Ubuntu 또는 Debian의 경우, 다른 배포판의 경우 Google에서 검색):
sudo apt install makepasswd