Home | 简体中文 | 繁体中文 | 杂文 | Github | 知乎专栏 | Facebook | Linkedin | Youtube | 打赏(Donations) | About
知乎专栏

3.2. getent 用来察看系统的数据库中的相关记录

支持数据库

    	
ahosts ahostsv4 ahostsv6 aliases ethers group gshadow hosts initgroups
netgroup networks passwd protocols rpc services shadow    	
    	
		

3.2.1. 主机名

查找主机名

			
[root@localhost ~]# getent hosts localhost
::1             localhost localhost.localdomain localhost6 localhost6.localdomain6		

[root@localhost ~]# getent hosts localhost.localdomain
::1             localhost localhost.localdomain localhost6 localhost6.localdomain6	
			
			

3.2.2. 用户组

查看用户

			
[root@localhost ~]# getent passwd halt
halt:x:7:0:halt:/sbin:/sbin/halt		

[root@localhost ~]# getent passwd `whoami`
root:x:0:0:root:/root:/bin/bash	
			
			

通过UID查看用户信息

			
[root@localhost ~]# getent passwd 65534
nobody:x:65534:65534:Kernel Overflow User:/:/sbin/nologin			
			
			

判定用户组test是否存在:如果存在就退出,不存在就创建

			
[root@localhost ~]# getent group test || groupadd test

[root@localhost ~]# getent group zabbix > /dev/null || groupadd -r zabbix
[root@localhost ~]# getent passwd zabbix > /dev/null || useradd -r -g zabbix -s /sbin/nologin -c "Zabbix Monitoring System" zabbix	
			
			

3.2.3. 查看端口

			
[root@localhost ~]# getent services 22
ssh                   22/tcp
[root@localhost ~]# getent services 80
http                  80/tcp www www-http
[root@localhost ~]# getent services 443
https                 443/tcp			
			
			

3.2.4. shadow 密码

			
[root@localhost ~]# getent shadow root
root:$6$PlAA9lHTPmwOO8TL$1cjrer572Zbw.1nR4TvWRZRdRFuNgNxJayh4snUtqGZ6brTZNOyzWHfFUFptXUGjDgxqdrAtweeIuWbvbmtuQ1::0:99999:7:::

[root@localhost ~]# getent shadow sshd
sshd:!!:18229::::::