mirror of
https://github.com/LCTT/TranslateProject.git
synced 2025-01-13 22:30:37 +08:00
20151019-2 选题
This commit is contained in:
parent
492bf330a8
commit
f647aa1f47
146
sources/tech/20151019 10 passwd command examples in Linux.md
Normal file
146
sources/tech/20151019 10 passwd command examples in Linux.md
Normal file
@ -0,0 +1,146 @@
|
||||
10 passwd command examples in Linux
|
||||
================================================================================
|
||||
As the name suggest **passwd** command is used to change the password of system users. If the passwd command is executed by non-root user then it will ask for the current password and then set the new password of a user who invoked the command. When this command is executed by super user or root then it can reset the password for any user including root without knowing the current password.
|
||||
|
||||
In this post we will discuss passwd command with practical examples.
|
||||
|
||||
#### Syntax : ####
|
||||
|
||||
# passwd {options} {user_name}
|
||||
|
||||
Different options that can be used in passwd command are listed below :
|
||||
|
||||
![](http://www.linuxtechi.com/wp-content/uploads/2015/09/passwd-command-options.jpg)
|
||||
|
||||
### Example:1 Change Password of System Users ###
|
||||
|
||||
When you logged in as non-root user like ‘linuxtechi’ in my case and run passwd command then it will reset password of logged in user.
|
||||
|
||||
[linuxtechi@linuxworld ~]$ passwd
|
||||
Changing password for user linuxtechi.
|
||||
Changing password for linuxtechi.
|
||||
(current) UNIX password:
|
||||
New password:
|
||||
Retype new password:
|
||||
passwd: all authentication tokens updated successfully.
|
||||
[linuxtechi@linuxworld ~]$
|
||||
|
||||
When you logged in as root user and run **passwd** command then it will reset the root password by default and if you specify the user-name after passwd command then it will change the password of that user.
|
||||
|
||||
[root@linuxworld ~]# passwd
|
||||
[root@linuxworld ~]# passwd linuxtechi
|
||||
|
||||
![](http://www.linuxtechi.com/wp-content/uploads/2015/09/passwd-command.jpg)
|
||||
|
||||
**Note** : System user’s password is stored in an encrypted form in /etc/shadow file.
|
||||
|
||||
### Example:2 Display Password Status Information. ###
|
||||
|
||||
To display password status information of a user , use **-S** option in passwd command.
|
||||
|
||||
[root@linuxworld ~]# passwd -S linuxtechi
|
||||
linuxtechi PS 2015-09-20 0 99999 7 -1 (Password set, SHA512 crypt.)
|
||||
[root@linuxworld ~]#
|
||||
|
||||
In the above output first field shows the user name and second field shows Password status ( **PS = Password Set , LK = Password locked , NP = No Password** ), third field shows when the password was changed and last & fourth field shows minimum age, maximum age, warning period, and inactivity period for the password
|
||||
|
||||
### Example:3 Display Password Status info for all the accounts ###
|
||||
|
||||
To display password status info for all the accounts use “**-aS**” option in passwd command, example is shown below :
|
||||
|
||||
root@localhost:~# passwd -Sa
|
||||
|
||||
![](http://www.linuxtechi.com/wp-content/uploads/2015/09/passwd-sa.jpg)
|
||||
|
||||
### Example:4 Removing Password of a User using -d option ###
|
||||
|
||||
In my case i am removing/ deleting the password of ‘**linuxtechi**‘ user.
|
||||
|
||||
[root@linuxworld ~]# passwd -d linuxtechi
|
||||
Removing password for user linuxtechi.
|
||||
passwd: Success
|
||||
[root@linuxworld ~]#
|
||||
[root@linuxworld ~]# passwd -S linuxtechi
|
||||
linuxtechi NP 2015-09-20 0 99999 7 -1 (Empty password.)
|
||||
[root@linuxworld ~]#
|
||||
|
||||
“**-d**” option will make user’s password empty and will disable user’s account.
|
||||
|
||||
### Example:5 Set Password Expiry Immediately ###
|
||||
|
||||
Use ‘-e’ option in passwd command to expire user’s password immediately , this will force the user to change the password in the next login.
|
||||
|
||||
[root@linuxworld ~]# passwd -e linuxtechi
|
||||
Expiring password for user linuxtechi.
|
||||
passwd: Success
|
||||
[root@linuxworld ~]# passwd -S linuxtechi
|
||||
linuxtechi PS 1970-01-01 0 99999 7 -1 (Password set, SHA512 crypt.)
|
||||
[root@linuxworld ~]#
|
||||
|
||||
Now Try to ssh machine using linuxtechi user.
|
||||
|
||||
![](http://www.linuxtechi.com/wp-content/uploads/2015/09/passwd-expiry.jpg)
|
||||
|
||||
### Example:6 Lock the password of System User ###
|
||||
|
||||
Use ‘**-l**‘ option in passwd command to lock a user’s password, it will add “!” at starting of user’s password. A User can’t Change it’s password when his/her password is locked.
|
||||
|
||||
[root@linuxworld ~]# passwd -l linuxtechi
|
||||
Locking password for user linuxtechi.
|
||||
passwd: Success
|
||||
[root@linuxworld ~]# passwd -S linuxtechi
|
||||
linuxtechi LK 2015-09-20 0 99999 7 -1 (Password locked.)
|
||||
[root@linuxworld ~]#
|
||||
|
||||
### Example:7 Unlock User’s Password using -u option ###
|
||||
|
||||
[root@linuxworld ~]# passwd -u linuxtechi
|
||||
Unlocking password for user linuxtechi.
|
||||
passwd: Success
|
||||
[root@linuxworld ~]#
|
||||
|
||||
### Example:8 Setting inactive days using -i option ###
|
||||
|
||||
-i option in passwd command is used to set inactive days for a system user. This will come into the picture when password of user ( in my case linuxtechi) expired and user didn’t change its password in ‘**n**‘ number of days ( i.e 10 days in my case) then after that user will not able to login.
|
||||
|
||||
[root@linuxworld ~]# passwd -i 10 linuxtechi
|
||||
Adjusting aging data for user linuxtechi.
|
||||
passwd: Success
|
||||
[root@linuxworld ~]#
|
||||
[root@linuxworld ~]# passwd -S linuxtechi
|
||||
linuxtechi PS 2015-09-20 0 99999 7 10 (Password set, SHA512 crypt.)
|
||||
[root@linuxworld ~]#
|
||||
|
||||
### Example:9 Set Minimum Days to Change Password using -n option. ###
|
||||
|
||||
In the below example linuxtechi user has to change the password in 90 days. A value of zero shows that user can change it’s password in any time.
|
||||
|
||||
[root@linuxworld ~]# passwd -n 90 linuxtechi
|
||||
Adjusting aging data for user linuxtechi.
|
||||
passwd: Success
|
||||
[root@linuxworld ~]# passwd -S linuxtechi
|
||||
linuxtechi PS 2015-09-20 90 99999 7 10 (Password set, SHA512 crypt.)
|
||||
[root@linuxworld ~]#
|
||||
|
||||
### Example:10 Set Warning days before password expire using -w option ###
|
||||
|
||||
‘**-w**’ option in passwd command is used to set warning days for a user. It means a user will be warned for n number of days that his/her password is going to expire.
|
||||
|
||||
[root@linuxworld ~]# passwd -w 12 linuxtechi
|
||||
Adjusting aging data for user linuxtechi.
|
||||
passwd: Success
|
||||
[root@linuxworld ~]# passwd -S linuxtechi
|
||||
linuxtechi PS 2015-09-20 90 99999 12 10 (Password set, SHA512 crypt.)
|
||||
[root@linuxworld ~]#
|
||||
|
||||
--------------------------------------------------------------------------------
|
||||
|
||||
via: http://www.linuxtechi.com/10-passwd-command-examples-in-linux/
|
||||
|
||||
作者:[Pradeep Kumar][a]
|
||||
译者:[译者ID](https://github.com/译者ID)
|
||||
校对:[校对者ID](https://github.com/校对者ID)
|
||||
|
||||
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出
|
||||
|
||||
[a]:http://www.linuxtechi.com/author/pradeep/
|
258
sources/tech/20151019 11 df command examples in Linux.md
Normal file
258
sources/tech/20151019 11 df command examples in Linux.md
Normal file
@ -0,0 +1,258 @@
|
||||
11 df command examples in Linux
|
||||
================================================================================
|
||||
df (disk free) command is used to display disk usage of the file system. By default df command shows the file system usage in 1K blocks for all the current mounted file system, if you want to display the output of df command in human readable format , use -h option like “df -h”.
|
||||
|
||||
In this post we will discuss 11 different examples of ‘**df**‘ command in Linux
|
||||
|
||||
Basic Format of df command in Linux
|
||||
|
||||
# df {options} {mount_point_of_filesystem}
|
||||
|
||||
Options used in df command :
|
||||
|
||||
![](http://www.linuxtechi.com/wp-content/uploads/2015/10/df-command-options.jpg)
|
||||
|
||||
Sample Output of df :
|
||||
|
||||
[root@linux-world ~]# df
|
||||
Filesystem 1K-blocks Used Available Use% Mounted on
|
||||
/dev/mapper/vg00-root 17003304 804668 15311852 5% /
|
||||
devtmpfs 771876 0 771876 0% /dev
|
||||
tmpfs 777928 0 777928 0% /dev/shm
|
||||
tmpfs 777928 8532 769396 2% /run
|
||||
tmpfs 777928 0 777928 0% /sys/fs/cgroup
|
||||
/dev/mapper/vg00-home 14987616 41000 14162232 1% /home
|
||||
/dev/sda1 487652 62593 395363 14% /boot
|
||||
/dev/mapper/vg00-var 9948012 48692 9370936 1% /var
|
||||
/dev/mapper/vg00-sap 14987656 37636 14165636 1% /sap
|
||||
[root@linux-world ~]#
|
||||
|
||||
### Example:1 List disk usage of all the file system using ‘-a’ ###
|
||||
|
||||
when we use ‘-a’ option in df command , it will display disk usage of all the file systems.
|
||||
|
||||
[root@linux-world ~]# df -a
|
||||
Filesystem 1K-blocks Used Available Use% Mounted on
|
||||
rootfs 17003304 804668 15311852 5% /
|
||||
proc 0 0 0 - /proc
|
||||
sysfs 0 0 0 - /sys
|
||||
devtmpfs 771876 0 771876 0% /dev
|
||||
securityfs 0 0 0 - /sys/kernel/security
|
||||
tmpfs 777928 0 777928 0% /dev/shm
|
||||
devpts 0 0 0 - /dev/pts
|
||||
tmpfs 777928 8532 769396 2% /run
|
||||
tmpfs 777928 0 777928 0% /sys/fs/cgroup
|
||||
cgroup 0 0 0 - /sys/fs/cgroup/systemd
|
||||
pstore 0 0 0 - /sys/fs/pstore
|
||||
cgroup 0 0 0 - /sys/fs/cgroup/cpuset
|
||||
cgroup 0 0 0 - /sys/fs/cgroup/cpu,cpuacct
|
||||
cgroup 0 0 0 - /sys/fs/cgroup/memory
|
||||
cgroup 0 0 0 - /sys/fs/cgroup/devices
|
||||
cgroup 0 0 0 - /sys/fs/cgroup/freezer
|
||||
cgroup 0 0 0 - /sys/fs/cgroup/net_cls
|
||||
cgroup 0 0 0 - /sys/fs/cgroup/blkio
|
||||
cgroup 0 0 0 - /sys/fs/cgroup/perf_event
|
||||
cgroup 0 0 0 - /sys/fs/cgroup/hugetlb
|
||||
configfs 0 0 0 - /sys/kernel/config
|
||||
/dev/mapper/vg00-root 17003304 804668 15311852 5% /
|
||||
selinuxfs 0 0 0 - /sys/fs/selinux
|
||||
systemd-1 0 0 0 - /proc/sys/fs/binfmt_misc
|
||||
debugfs 0 0 0 - /sys/kernel/debug
|
||||
hugetlbfs 0 0 0 - /dev/hugepages
|
||||
mqueue 0 0 0 - /dev/mqueue
|
||||
/dev/mapper/vg00-home 14987616 41000 14162232 1% /home
|
||||
/dev/sda1 487652 62593 395363 14% /boot
|
||||
/dev/mapper/vg00-var 9948012 48692 9370936 1% /var
|
||||
/dev/mapper/vg00-sap 14987656 37636 14165636 1% /sap
|
||||
[root@linux-world ~]#
|
||||
|
||||
### Example:2 Display the output of df command in human readable format. ###
|
||||
|
||||
Using ‘-h’ option in df command , output can be displayed in human readable format ( e.g 5K , 500M & 5G )
|
||||
|
||||
[root@linux-world ~]# df -h
|
||||
Filesystem Size Used Avail Use% Mounted on
|
||||
/dev/mapper/vg00-root 17G 786M 15G 5% /
|
||||
devtmpfs 754M 0 754M 0% /dev
|
||||
tmpfs 760M 0 760M 0% /dev/shm
|
||||
tmpfs 760M 8.4M 752M 2% /run
|
||||
tmpfs 760M 0 760M 0% /sys/fs/cgroup
|
||||
/dev/mapper/vg00-home 15G 41M 14G 1% /home
|
||||
/dev/sda1 477M 62M 387M 14% /boot
|
||||
/dev/mapper/vg00-var 9.5G 48M 9.0G 1% /var
|
||||
/dev/mapper/vg00-sap 15G 37M 14G 1% /sap
|
||||
[root@linux-world ~]#
|
||||
|
||||
### Example:3 Display Space usage of particular file system ###
|
||||
|
||||
Suppose we want to print space usage of /sap file system,
|
||||
|
||||
[root@linux-world ~]# df -h /sap/
|
||||
Filesystem Size Used Avail Use% Mounted on
|
||||
/dev/mapper/vg00-sap 15G 37M 14G 1% /sap
|
||||
[root@linux-world ~]#
|
||||
|
||||
### Example:4 Print file system type of all mounted file systems ###
|
||||
|
||||
‘**-T**’ is used in df command to display the file system type in the output.
|
||||
|
||||
[root@linux-world ~]# df -T
|
||||
Filesystem Type 1K-blocks Used Available Use% Mounted on
|
||||
/dev/mapper/vg00-root ext4 17003304 804668 15311852 5% /
|
||||
devtmpfs devtmpfs 771876 0 771876 0% /dev
|
||||
tmpfs tmpfs 777928 0 777928 0% /dev/shm
|
||||
tmpfs tmpfs 777928 8532 769396 2% /run
|
||||
tmpfs tmpfs 777928 0 777928 0% /sys/fs/cgroup
|
||||
/dev/mapper/vg00-home ext4 14987616 41000 14162232 1% /home
|
||||
/dev/sda1 ext3 487652 62593 395363 14% /boot
|
||||
/dev/mapper/vg00-var ext3 9948012 48696 9370932 1% /var
|
||||
/dev/mapper/vg00-sap ext3 14987656 37636 14165636 1% /sap
|
||||
[root@linux-world ~]#
|
||||
|
||||
### Example:5 Print disk usage of file systems in block-size. ###
|
||||
|
||||
[root@linux-world ~]# df -k
|
||||
Filesystem 1K-blocks Used Available Use% Mounted on
|
||||
/dev/mapper/vg00-root 17003304 804668 15311852 5% /
|
||||
devtmpfs 771876 0 771876 0% /dev
|
||||
tmpfs 777928 0 777928 0% /dev/shm
|
||||
tmpfs 777928 8532 769396 2% /run
|
||||
tmpfs 777928 0 777928 0% /sys/fs/cgroup
|
||||
/dev/mapper/vg00-home 14987616 41000 14162232 1% /home
|
||||
/dev/sda1 487652 62593 395363 14% /boot
|
||||
/dev/mapper/vg00-var 9948012 48696 9370932 1% /var
|
||||
/dev/mapper/vg00-sap 14987656 37636 14165636 1% /sap
|
||||
[root@linux-world ~]#
|
||||
|
||||
### Example:6 Display inodes information of file system. ###
|
||||
|
||||
‘**-i**’ option in df command is used to display inode information of the file system
|
||||
|
||||
inodes info of all the file system :
|
||||
|
||||
[root@linux-world ~]# df -i
|
||||
Filesystem Inodes IUsed IFree IUse% Mounted on
|
||||
/dev/mapper/vg00-root 1089536 22031 1067505 3% /
|
||||
devtmpfs 192969 357 192612 1% /dev
|
||||
tmpfs 194482 1 194481 1% /dev/shm
|
||||
tmpfs 194482 420 194062 1% /run
|
||||
tmpfs 194482 13 194469 1% /sys/fs/cgroup
|
||||
/dev/mapper/vg00-home 960992 15 960977 1% /home
|
||||
/dev/sda1 128016 337 127679 1% /boot
|
||||
/dev/mapper/vg00-var 640848 1235 639613 1% /var
|
||||
/dev/mapper/vg00-sap 960992 11 960981 1% /sap
|
||||
[root@linux-world ~]#
|
||||
|
||||
inodes info of particular file system :
|
||||
|
||||
[root@linux-world ~]# df -i /sap/
|
||||
Filesystem Inodes IUsed IFree IUse% Mounted on
|
||||
/dev/mapper/vg00-sap 960992 11 960981 1% /sap
|
||||
[root@linux-world ~]#
|
||||
|
||||
### Example:7 Print grant total space usage of all file system. ###
|
||||
|
||||
‘–total‘ option in df command is used to display the grant total of disk usage of all the file system.
|
||||
|
||||
[root@linux-world ~]# df -h --total
|
||||
Filesystem Size Used Avail Use% Mounted on
|
||||
/dev/mapper/vg00-root 17G 786M 15G 5% /
|
||||
devtmpfs 754M 0 754M 0% /dev
|
||||
tmpfs 760M 0 760M 0% /dev/shm
|
||||
tmpfs 760M 8.4M 752M 2% /run
|
||||
tmpfs 760M 0 760M 0% /sys/fs/cgroup
|
||||
/dev/mapper/vg00-home 15G 41M 14G 1% /home
|
||||
/dev/sda1 477M 62M 387M 14% /boot
|
||||
/dev/mapper/vg00-var 9.5G 48M 9.0G 1% /var
|
||||
/dev/mapper/vg00-sap 15G 37M 14G 1% /sap
|
||||
total 58G 980M 54G 2% -
|
||||
[root@linux-world ~]#
|
||||
|
||||
### Example:8 Print only Local file system space usage info. ###
|
||||
|
||||
Suppose network file system also mounted on linux box and but we want to display local file system information only, this can be achieved by using ‘-l‘ option in df command.
|
||||
|
||||
![](http://www.linuxtechi.com/wp-content/uploads/2015/10/nfs4-fs-mount.jpg)
|
||||
|
||||
Limiting to local file system :
|
||||
|
||||
[root@linux-world ~]# df -Thl
|
||||
Filesystem Type Size Used Avail Use% Mounted on
|
||||
/dev/mapper/vg00-root ext4 17G 791M 15G 6% /
|
||||
devtmpfs devtmpfs 754M 0 754M 0% /dev
|
||||
tmpfs tmpfs 760M 0 760M 0% /dev/shm
|
||||
tmpfs tmpfs 760M 8.4M 752M 2% /run
|
||||
tmpfs tmpfs 760M 0 760M 0% /sys/fs/cgroup
|
||||
/dev/mapper/vg00-home ext4 15G 41M 14G 1% /home
|
||||
/dev/sda1 ext3 477M 62M 387M 14% /boot
|
||||
/dev/mapper/vg00-var ext3 9.5G 105M 8.9G 2% /var
|
||||
/dev/mapper/vg00-sap ext3 15G 37M 14G 1% /sap
|
||||
[root@linux-world ~]#
|
||||
|
||||
### Example:9 Print Disk Space information of particular file system type. ###
|
||||
|
||||
‘**-t**’ option in df command is used to print information of particular file system type, after ‘-t’ specify the file system type, example is shown below :
|
||||
|
||||
for ext4 :
|
||||
|
||||
[root@linux-world ~]# df -t ext4
|
||||
Filesystem 1K-blocks Used Available Use% Mounted on
|
||||
/dev/mapper/vg00-root 17003304 809492 15307028 6% /
|
||||
/dev/mapper/vg00-home 14987616 41000 14162232 1% /home
|
||||
[root@linux-world ~]#
|
||||
|
||||
for nfs4 :
|
||||
|
||||
[root@linux-world ~]# df -t nfs4
|
||||
Filesystem 1K-blocks Used Available Use% Mounted on
|
||||
192.168.1.5:/opensuse 301545472 266833920 19371008 94% /data
|
||||
[root@linux-world ~]#
|
||||
|
||||
### Example:10 Exclude Particular file system type using ‘-x’ option ###
|
||||
|
||||
“**-x** or **–exclude-type**” is used to exclude the certain file system type in the output of df command.
|
||||
|
||||
Let suppose we want to print all the file systems excluding ext3 file system.
|
||||
|
||||
[root@linux-world ~]# df -x ext3
|
||||
Filesystem 1K-blocks Used Available Use% Mounted on
|
||||
/dev/mapper/vg00-root 17003304 809492 15307028 6% /
|
||||
devtmpfs 771876 0 771876 0% /dev
|
||||
tmpfs 777928 0 777928 0% /dev/shm
|
||||
tmpfs 777928 8540 769388 2% /run
|
||||
tmpfs 777928 0 777928 0% /sys/fs/cgroup
|
||||
/dev/mapper/vg00-home 14987616 41000 14162232 1% /home
|
||||
192.168.1.5:/opensuse 301545472 266834944 19369984 94% /data
|
||||
[root@linux-world ~]#
|
||||
|
||||
### Example:11 Print only certain fields in output of df command. ###
|
||||
|
||||
‘**–output={field_name1,field_name2….}**‘ option is used to display the certain fields in df command output.
|
||||
|
||||
Valid field names are: ‘source’, ‘fstype’, ‘itotal’, ‘iused’, ‘iavail’, ‘ipcent’, ‘size’, ‘used’, ‘avail’, ‘pcent’ and ‘target’
|
||||
|
||||
[root@linux-world ~]# df --output=fstype,size,iused
|
||||
Type 1K-blocks IUsed
|
||||
ext4 17003304 22275
|
||||
devtmpfs 771876 357
|
||||
tmpfs 777928 1
|
||||
tmpfs 777928 423
|
||||
tmpfs 777928 13
|
||||
ext4 14987616 15
|
||||
ext3 487652 337
|
||||
ext3 9948012 1373
|
||||
ext3 14987656 11
|
||||
nfs4 301545472 451099
|
||||
[root@linux-world ~]#
|
||||
|
||||
--------------------------------------------------------------------------------
|
||||
|
||||
via: http://www.linuxtechi.com/11-df-command-examples-in-linux/
|
||||
|
||||
作者:[Pradeep Kumar][a]
|
||||
译者:[译者ID](https://github.com/译者ID)
|
||||
校对:[校对者ID](https://github.com/校对者ID)
|
||||
|
||||
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出
|
||||
|
||||
[a]:http://www.linuxtechi.com/author/pradeep/
|
Loading…
Reference in New Issue
Block a user