viso1998
V2EX  ›  问与答

如何通过 shell 脚本更改 root 密码?

  •  
  •   viso1998 · Jan 16, 2018 · 3964 views
    This topic created in 3130 days ago, the information mentioned may be changed or developed.

    当前用户是 ubuntu,如何通过脚本更改 root 用户密码?请各位大神指点

    9 replies    2018-01-16 16:40:30 +08:00
    Vicer
        1
    Vicer  
       Jan 16, 2018 via Android
    viso1998
        2
    viso1998  
    OP
       Jan 16, 2018
    @Vicer 感谢!
    viso1998
        3
    viso1998  
    OP
       Jan 16, 2018
    @Vicer 这个好像密码中不能包含$?
    mt7620
        4
    mt7620  
       Jan 16, 2018
    echo 'root:rootpassword' | chpasswd
    swulling
        5
    swulling  
       Jan 16, 2018
    echo "root:password" | chpasswd
    viso1998
        6
    viso1998  
    OP
       Jan 16, 2018
    @mt7620 @swulling 感谢回复,密码中包含$特殊字符的写法应该是:echo 'root:xx$xx' | sudo chpasswd root
    initdrv
        7
    initdrv  
       Jan 16, 2018
    echo "pwd" | passwd --stdin root
    swulling
        8
    swulling  
       Jan 16, 2018 via iPhone
    @viso1998 $是 shell 变量提示符,用单引号正解
    viso1998
        9
    viso1998  
    OP
       Jan 16, 2018
    @swulling 再请教一下,可以在 shell 脚本中切换成 root 用户身份吗?
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Solana   ·   1186 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 27ms · UTC 23:39 · PVG 07:39 · LAX 16:39 · JFK 19:39
    ♥ Do have faith in what you're doing.