useradd -p オプション [重複]

useradd -p オプション [重複]

「useradd」では、-pオプションの目的を理解できません。
ユーザーを作成してみましょう。

useradd -m -p 'pass1' user1 

上記のコマンドを実行した後、認証を使用してログインしようとするとsu - user1 失敗します。もう1つの問題は、パスワードが/ etc / passwdファイルで暗号化されていないことです。実行するcat /etc/passwd | grep user1user1:pass1:19196:0:99999:7:::

ベストアンサー1

-pこのオプションには暗号化されたパスワードを指定する必要があります。useradd(8)マニュアルページから:

       -p, --password PASSWORD
           The encrypted password, as returned by crypt(3). The 
           default is to disable the password.

           Note: This option is not recommended because the password
           (or encrypted password) will be visible by users listing 
           the processes.

指定した値はファイル内でそのまま使用されるため、暗号化さpasswdれていない値を指定した場合はパスワードでログインできません。


次のように動作します。

useradd -m \
  -p "$(python -c 'import crypt; print(crypt.crypt("pass1"))')" \
  testuser

(ただし、他のシステムユーザーにパスワードが漏洩する可能性があるという警告は、マニュアルページに記載されています。)

おすすめ記事