forked from digidem/filehub-config
-
Notifications
You must be signed in to change notification settings - Fork 4
/
ChangeRootPassword.sh
56 lines (45 loc) · 1.76 KB
/
ChangeRootPassword.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
#!/bin/sh
# Change the root password only!
# ---------------------------------------------------------------
# INSTRUCTIONS:
# Copy the script to your SD card.
# Login as *root* (using the old password).
# cd /data/UsbDisk1/Volume1
# sh ChangeRootPassword.sh
# Enter your new password twice.
# Carefully check the output. (You know how to reset the device?)
# If you are absolutely sure, write your changes
# /usr/sbin/etc_tools p
# ---------------------------------------------------------------
# With WD-02 firmware 2.000.014, "passwd" only modifies /etc/shadow
# but telnetd still uses /etc/passwd, apparently.
# Please use the web interface to change the user (admin) password
# as this goes into multiple places - and the web interface does
# change both /etc/passwd and /etc/shadow!
# passwd does NOT accept stdin from a file, therefore this script
# cannot be included into EnterRouterMode.sh!
echo pre-change:
date
ls -l /etc/passwd /etc/shadow
grep ^root: /etc/passwd /etc/shadow
passwd
echo in-change:
date
ls -l /etc/passwd /etc/shadow
grep ^root: /etc/passwd /etc/shadow
# This changed the second field in /etc/shadow, extract it
ENCPASS=`awk -F: '/^root:/{print $2}' /etc/shadow`
echo encrypted password: $ENCPASS
OLDPASS=`awk -F: '/^root:/{print $2}' /etc/passwd`
echo overwriting old password: $OLDPASS
cp -p /etc/passwd /etc/passwd-
# 20150905: change shell to /bin/sh (fw .020 and up)
awk -F: -vPASS="$ENCPASS" \
'{if(/^root:/){$2=PASS;$7="/bin/sh"}printf("%s:%s:%s:%s:%s:%s:%s\n",$1,$2,$3,$4,$5,$6,$7)}' \
/etc/passwd- > /etc/passwd
echo post-change:
date
ls -l /etc/passwd /etc/shadow
grep ^root: /etc/passwd /etc/shadow
echo "Now check whether you can actually use this password."
echo "Do not forget to SAVE your changes using \"/usr/sbin/etc_tools p\" !"