設定使用者密碼

  1. passwd 命令設定或變更密碼
    [root@kvm8 ~]# passwd --help
    Usage: passwd [options] [LOGIN]
    
    Options:
      -a, --all                     report password status on all accounts
      -d, --delete                  delete the password for the named account
      -e, --expire                  force expire the password for the named account
      -h, --help                    display this help message and exit
      -k, --keep-tokens             change password only if expired
      -i, --inactive INACTIVE       set password inactive after expiration
                                    to INACTIVE
      -l, --lock                    lock the password of the named account
      -n, --mindays MIN_DAYS        set minimum number of days before password
                                    change to MIN_DAYS
      -q, --quiet                   quiet mode
      -r, --repository REPOSITORY   change password in REPOSITORY repository
      -R, --root CHROOT_DIR         directory to chroot into
      -P, --prefix PREFIX_DIR       directory prefix
      -S, --status                  report password status on the named account
      -u, --unlock                  unlock the password of the named account
      -w, --warndays WARN_DAYS      set expiration warning days to WARN_DAYS
      -x, --maxdays MAX_DAYS        set maximum number of days before password
                                    change to MAX_DAYS
      -s, --stdin                   read new token from stdin
    
    參數:
    --stdin  :經由標準輸入取得密碼,配合管線處理,可大量更改帳號密碼。
    
  2. 使用 --stdin 選項設定 deyu1, deyu2, deyu3, deyu4 的密碼。
    [root@kvm8 ~]# echo 123qwe | passwd --stdin deyu1
    BAD PASSWORD: The password is shorter than 8 characters
    [root@kvm8 ~]# echo 123qwe | passwd --stdin deyu2
    BAD PASSWORD: The password is shorter than 8 characters
    [root@kvm8 ~]# echo 123qwe | passwd --stdin deyu3
    BAD PASSWORD: The password is shorter than 8 characters
    [root@kvm8 ~]# echo 123qwe | passwd --stdin deyu4
    BAD PASSWORD: The password is shorter than 8 characters
    
  3. ssh deyu1 測試密碼,登入成功。
    [root@kvm8 ~]# ssh deyu1@kvm8
    The authenticity of host 'kvm8 (192.168.122.8)' can't be established.
    ED25519 key fingerprint is SHA256:UW9HYWrgRRWBjnpqAMPE+Nu4eM1K1FyU15owqZ5YVsw.
    This key is not known by any other names.
    Are you sure you want to continue connecting (yes/no/[fingerprint])? yes
    Warning: Permanently added 'kvm8' (ED25519) to the list of known hosts.
    deyu1@kvm8's password:
    
  4. 登出 deyu1。
    [deyu1@kvm8 ~]$
    logout
    Connection to kvm8 closed.