2012. 6. 12. 11:12

/etc/passw파일에 정의되어 있는 모든 계정의 최근접속정보를 확인하는 명령어입니다.
주로 서버의 보안점검을 위하여 필수적으로 확인해보아야하는 명령어입니다.
간단히 lastlog라고만 하면 모든 계정의 마지막 접속정보를 출력해줍니다.



사용형식

       lastlog [-u login-name] [-t days]



사용예 #1

간단히 lastlog라고만 하면 다음과 같이 서버의 모든 계정에 대한 최근접속정보를 확인할 수 있습니다.

[root@host3 bin]# lastlog
Username         Port     From             Latest
root             pts/1    192.168.0.2      금 10월  3 22:08:03 +0900 2003
bin                                        **Never logged in**
daemon                                     **Never logged in**
adm                                        **Never logged in**
lp                                         **Never logged in**
sync                                       **Never logged in**
shutdown                                   **Never logged in**
halt                                       **Never logged in**
mail                                       **Never logged in**
news                                       **Never logged in**
uucp                                       **Never logged in**
operator                                   **Never logged in**
games                                      **Never logged in**
gopher                                     **Never logged in**
ftp                                        **Never logged in**
nobody                                     **Never logged in**
ntp                                        **Never logged in**
rpc                                        **Never logged in**
vcsa                                       **Never logged in**
nscd                                       **Never logged in**
sshd                                       **Never logged in**
rpm                                        **Never logged in**
mailnull                                   **Never logged in**
smmsp                                      **Never logged in**
rpcuser                                    **Never logged in**
nfsnobody                                  **Never logged in**
pcap                                       **Never logged in**
xfs                                        **Never logged in**
wnn                                        **Never logged in**
named                                      **Never logged in**
gdm                                        **Never logged in**
desktop                                    **Never logged in**
postgres                                   **Never logged in**
apache                                     **Never logged in**
postfix                                    **Never logged in**
squid                                      **Never logged in**
webalizer                                  **Never logged in**
bible            pts/2    192.168.0.2      목  9월 18 23:44:18 +0900 2003
bible1           pts/2    192.168.0.202    목  9월 18 23:46:11 +0900 2003
bible2           pts/3    192.168.0.111    목  9월 18 23:46:56 +0900 2003
sspark                                     **Never logged in**
bible5                                     **Never logged in**
mysql                                      **Never logged in**
[root@host3 bin]#



사용예 #2

만약 특정계정만의 최근접속정보를 확인하고자 한다면 다음과 같이 -u 옵션과 함께 사용하시면 됩니다.  

[root@host3 bin]# lastlog -u bible
Username         Port     From             Latest
bible            pts/2    192.168.0.2      목  9월 18 23:44:18 +0900 2003
[root@host3 bin]#

사용예 #3

lastlog는 최근 몇일까지의 마지막접속정보를 확인할 수도 있습니다. 다음은 최근 30일까지의 최근접속정보를 확인한 것입니다.

[root@host3 bin]# lastlog -t 30
Username         Port     From             Latest
root             pts/1    192.168.0.2      금 10월  3 22:08:03 +0900 2003
bible            pts/2    192.168.0.2      목  9월 18 23:44:18 +0900 2003
bible1           pts/2    192.168.0.202    목  9월 18 23:46:11 +0900 2003
bible2           pts/3    192.168.0.111    목  9월 18 23:46:56 +0900 2003
[root@host3 bin]#

'UNIX > Linux' 카테고리의 다른 글

[Linux] 특정디렉토리내의 디렉토리리스트만 확인하기  (0) 2012.06.12
[Linux] perror  (0) 2012.06.12
[Linux] last  (0) 2012.06.12
[Linux] passwd  (0) 2012.06.12
[Linux] halt  (0) 2012.06.12
Posted by 몰라욧
2012. 6. 12. 11:10

서버를 이용하는 각 계정사용자들의 로그인정보를 보여주는 명령어입니다.
흔히 관리자는 각 계정별로 서버에 접속한 시간과 IP주소등을 확인해야할 경우가 있습니다.
또한 특정 계정의 서버 접속정보를 확인해야할때에도 마찬가지입니다.
아래 예를 보시면 알시겠지만 last는 다양한 방법으로 사용자들의 로그인정보를 조사합니다.




사용형식

       last [-R] [-num] [ -n num ] [-adiox] [ -f file ] [ -t YYYYMMDDHHMMSS ] [name...] [tty...]


사용예 #1

그냥 아래와 같이 last라고만 하면 시스템의 모든 접속정보를 볼 수 있습니다.
아래 예와 같이 아무런 옵션없이 그냥 "last"라고만 하면 모든 계정들의 접속정보를 보여줍니다.

[root@host3 log]# last
root     pts/0        192.168.0.2      Sat Oct  4 10:45   still logged in  
reboot   system boot  2.4.18-14        Sat Oct  4 10:29          (00:29)    
root     pts/1        192.168.0.2      Fri Oct  3 22:08 - down   (01:29)    
root     pts/0        192.168.0.2      Fri Oct  3 19:22 - 23:37  (04:14)    
reboot   system boot  2.4.18-14        Fri Oct  3 19:11          (04:26)    
root     pts/0        192.168.0.2      Thu Oct  2 21:16 - down   (00:00)    
root     pts/1                         Thu Oct  2 19:42 - down   (01:34)    
root     :0                            Thu Oct  2 19:42 - down   (01:34)    
root     pts/0        192.168.0.2      Thu Oct  2 19:33 - 21:16  (01:43)    
reboot   system boot  2.4.18-14        Thu Oct  2 19:20          (01:56)    
root     pts/1                         Thu Oct  2 19:18 - crash  (00:02)    
root     pts/0                         Thu Oct  2 19:17 - crash  (00:03)    
root     :0                            Thu Oct  2 19:16 - crash  (00:03)    
reboot   system boot  2.4.18-14        Thu Oct  2 19:15          (02:00)    
reboot   system boot  2.4.18-14        Thu Oct  2 18:59          (02:17)    
reboot   system boot  2.4.18-14        Thu Oct  2 18:51          (02:25)    
reboot   system boot  2.4.18-14        Thu Oct  2 18:42          (02:34)    
root     pts/1        192.168.0.2      Wed Oct  1 21:31 - down   (01:29)    

wtmp begins Wed Oct  1 18:46:52 2003
[root@host3 log]#


사용예 #2

아래예는 root의 접속정보만을 확인한 예입니다.

[root@host3 log]# last root  
root     pts/0        192.168.0.2      Sat Oct  4 10:45   still logged in  
root     pts/1        192.168.0.2      Fri Oct  3 22:08 - down   (01:29)    
root     pts/0        192.168.0.2      Fri Oct  3 19:22 - 23:37  (04:14)    
root     pts/0        192.168.0.2      Thu Oct  2 21:16 - down   (00:00)    
root     pts/1                         Thu Oct  2 19:42 - down   (01:34)    
root     :0                            Thu Oct  2 19:42 - down   (01:34)    
root     pts/0        192.168.0.2      Thu Oct  2 19:33 - 21:16  (01:43)    
root     pts/1                         Thu Oct  2 19:18 - crash  (00:02)    
root     pts/0                         Thu Oct  2 19:17 - crash  (00:03)    
root     :0                            Thu Oct  2 19:16 - crash  (00:03)    
root     pts/1        192.168.0.2      Wed Oct  1 21:31 - down   (01:29)    

wtmp begins Wed Oct  1 18:46:52 2003
[root@host3 log]#

사용예 #3

아래의 예는 5행의 결과만을 확인한 예입니다.

[root@host3 log]# last -5
bible    pts/1        192.168.0.2      Sat Oct  4 11:00 - 11:00  (00:00)    
bible    pts/1        192.168.0.2      Sat Oct  4 11:00 - 11:00  (00:00)    
bible    pts/1        192.168.0.2      Sat Oct  4 10:59 - 10:59  (00:00)    
root     pts/0        192.168.0.2      Sat Oct  4 10:45   still logged in  
reboot   system boot  2.4.18-14        Sat Oct  4 10:29          (00:31)    

wtmp begins Wed Oct  1 18:46:52 2003
[root@host3 log]#



사용예 #4

다음과 같이 -R옵션을 사용한 것으로서 last의 결과에서 호스트(IP주소)접속기록을 제외한 결과만을 보여준 예입니다.

[root@host3 log]# last -R    
bible    pts/1        Sat Oct  4 11:00 - 11:00  (00:00)    
bible    pts/1        Sat Oct  4 11:00 - 11:00  (00:00)    
bible    pts/1        Sat Oct  4 10:59 - 10:59  (00:00)    
root     pts/0        Sat Oct  4 10:45   still logged in  
reboot   system boot  Sat Oct  4 10:29          (00:32)    
root     pts/1        Fri Oct  3 22:08 - down   (01:29)    
root     pts/0        Fri Oct  3 19:22 - 23:37  (04:14)    
reboot   system boot  Fri Oct  3 19:11          (04:26)    
root     pts/0        Thu Oct  2 21:16 - down   (00:00)    
root     pts/1        Thu Oct  2 19:42 - down   (01:34)    
root     :0           Thu Oct  2 19:42 - down   (01:34)    
root     pts/0        Thu Oct  2 19:33 - 21:16  (01:43)    
reboot   system boot  Thu Oct  2 19:20          (01:56)    
root     pts/1        Thu Oct  2 19:18 - crash  (00:02)    
root     pts/0        Thu Oct  2 19:17 - crash  (00:03)    
root     :0           Thu Oct  2 19:16 - crash  (00:03)    
reboot   system boot  Thu Oct  2 19:15          (02:00)    
reboot   system boot  Thu Oct  2 18:59          (02:17)    
reboot   system boot  Thu Oct  2 18:51          (02:25)    
reboot   system boot  Thu Oct  2 18:42          (02:34)    
root     pts/1        Wed Oct  1 21:31 - down   (01:29)    

wtmp begins Wed Oct  1 18:46:52 2003
[root@host3 log]#

사용예 #5

다음은 -a옵션을 사용하여 last의 결과중 호스트(IP주소)정보를 맨 마지막에 보여준 예입니다.

[root@host3 log]# last -a
bible    pts/1        Sat Oct  4 11:00 - 11:00  (00:00)     192.168.0.2
bible    pts/1        Sat Oct  4 11:00 - 11:00  (00:00)     192.168.0.2
bible    pts/1        Sat Oct  4 10:59 - 10:59  (00:00)     192.168.0.2
root     pts/0        Sat Oct  4 10:45   still logged in    192.168.0.2
reboot   system boot  Sat Oct  4 10:29          (00:32)     2.4.18-14
root     pts/1        Fri Oct  3 22:08 - down   (01:29)     192.168.0.2
root     pts/0        Fri Oct  3 19:22 - 23:37  (04:14)     192.168.0.2
reboot   system boot  Fri Oct  3 19:11          (04:26)     2.4.18-14
root     pts/0        Thu Oct  2 21:16 - down   (00:00)     192.168.0.2
root     pts/1        Thu Oct  2 19:42 - down   (01:34)    
root     :0           Thu Oct  2 19:42 - down   (01:34)    
root     pts/0        Thu Oct  2 19:33 - 21:16  (01:43)     192.168.0.2
reboot   system boot  Thu Oct  2 19:20          (01:56)     2.4.18-14
root     pts/1        Thu Oct  2 19:18 - crash  (00:02)    
root     pts/0        Thu Oct  2 19:17 - crash  (00:03)    
root     :0           Thu Oct  2 19:16 - crash  (00:03)    
reboot   system boot  Thu Oct  2 19:15          (02:00)     2.4.18-14
reboot   system boot  Thu Oct  2 18:59          (02:17)     2.4.18-14
reboot   system boot  Thu Oct  2 18:51          (02:25)     2.4.18-14
reboot   system boot  Thu Oct  2 18:42          (02:34)     2.4.18-14
root     pts/1        Wed Oct  1 21:31 - down   (01:29)     192.168.0.2

wtmp begins Wed Oct  1 18:46:52 2003
[root@host3 log]#

사용예 #6

다음은 모든 결과중 외부에서 접속한 정보와 reboot에 관한 정보만을 보여줍니다.

[root@host3 log]# last -d
bible    pts/1        192.168.0.2      Sat Oct  4 11:00 - 11:00  (00:00)    
bible    pts/1        192.168.0.2      Sat Oct  4 11:00 - 11:00  (00:00)    
bible    pts/1        192.168.0.2      Sat Oct  4 10:59 - 10:59  (00:00)    
root     pts/0        192.168.0.2      Sat Oct  4 10:45   still logged in  
reboot   system boot  2.4.18-14        Sat Oct  4 10:29          (00:32)    
root     pts/1        192.168.0.2      Fri Oct  3 22:08 - down   (01:29)    
root     pts/0        192.168.0.2      Fri Oct  3 19:22 - 23:37  (04:14)    
reboot   system boot  2.4.18-14        Fri Oct  3 19:11          (04:26)    
root     pts/0        192.168.0.2      Thu Oct  2 21:16 - down   (00:00)    
root     pts/1                         Thu Oct  2 19:42 - down   (01:34)    
root     :0                            Thu Oct  2 19:42 - down   (01:34)    
root     pts/0        192.168.0.2      Thu Oct  2 19:33 - 21:16  (01:43)    
reboot   system boot  2.4.18-14        Thu Oct  2 19:20          (01:56)    
root     pts/1                         Thu Oct  2 19:18 - crash  (00:02)    
root     pts/0                         Thu Oct  2 19:17 - crash  (00:03)    
root     :0                            Thu Oct  2 19:16 - crash  (00:03)    
reboot   system boot  2.4.18-14        Thu Oct  2 19:15          (02:00)    
reboot   system boot  2.4.18-14        Thu Oct  2 18:59          (02:17)    
reboot   system boot  2.4.18-14        Thu Oct  2 18:51          (02:25)    
reboot   system boot  2.4.18-14        Thu Oct  2 18:42          (02:34)    
root     pts/1        192.168.0.2      Wed Oct  1 21:31 - down   (01:29)    

wtmp begins Wed Oct  1 18:46:52 2003
[root@host3 log]#

'UNIX > Linux' 카테고리의 다른 글

[Linux] perror  (0) 2012.06.12
[Linux] lastlog  (0) 2012.06.12
[Linux] passwd  (0) 2012.06.12
[Linux] halt  (0) 2012.06.12
[Linux] reboot  (0) 2012.06.12
Posted by 몰라욧
2012. 6. 12. 11:09
passwd파일의 원하는 정보만 확인하기

/etc/passwd파일에는 관리자가 원하는 중요한 정보들이 많이 있습니다.
우리는 이파일의 정보를 이용하여 원하는 정보만을 얻을 수 있습니다.

사용예 #1

현재 서버계정사용자들의 "계정명   UID   GID"정보만을 확인해야하는 경우에는 다음과 같이 하시면 됩니다. 즉 계정명이 $1에 해당하며 UID는 $3에 해당하고, GID는 $4에 해당하므로 다음과 같이 하시면 원하는 정보를 출력할 수 있습니다.

[root@host3 root]# cat /etc/passwd | awk -F: '{print $1"    "$3"     "$4}'
root    0     0
bin    1     1
daemon    2     2
adm    3     4
lp    4     7
sync    5     0
shutdown    6     0
halt    7     0
mail    8     12
news    9     13
uucp    10     14
operator    11     0
games    12     100
gopher    13     30
ftp    14     50
nobody    99     99
ntp    38     38
rpc    32     32
vcsa    69     69
nscd    28     28
sshd    74     74
rpm    37     37
mailnull    47     47
smmsp    51     51
rpcuser    29     29
nfsnobody    65534     65534
pcap    77     77
xfs    43     43
wnn    49     49
named    25     25
gdm    42     42
desktop    80     80
postgres    26     26
apache    48     48
postfix    89     89
squid    23     23
webalizer    67     67
bible    500     500
bible1    502     502
bible2    503     503
sspark    505     506
bible5    508     508
mysql    509     509
[root@host3 root]#

사용예 #2

다음은 각 계정명과 계정이 사용하는 홈디렉토리를 뽑아서 출력한 것입니다.

[root@host3 root]# cat /etc/passwd | awk -F: '{print $1"    "$6}'
root    /root
bin    /bin
daemon    /sbin
adm    /var/adm
lp    /var/spool/lpd
sync    /sbin
shutdown    /sbin
halt    /sbin
mail    /var/spool/mail
news    /etc/news
uucp    /var/spool/uucp
operator    /root
games    /usr/games
gopher    /var/gopher
ftp    /var/ftp
nobody    /
ntp    /etc/ntp
rpc    /
vcsa    /dev
nscd    /
sshd    /var/empty/sshd
rpm    /var/lib/rpm
mailnull    /var/spool/mqueue
smmsp    /var/spool/mqueue
rpcuser    /var/lib/nfs
nfsnobody    /var/lib/nfs
pcap    /var/arpwatch
xfs    /etc/X11/fs
wnn    /home/wnn
named    /var/named
gdm    /var/gdm
desktop    /var/lib/menu/kde
postgres    /var/lib/pgsql
apache    /var/www
postfix    /var/spool/postfix
squid    /var/spool/squid
webalizer    /var/www/html/usage
bible    /home/bible
bible1    /home/bible1
bible2    /home/bible2
sspark    /home/sspark
bible5    /usr/sspark5
mysql    /home/mysql
[root@host3 root]#

여러분께서는 위의예를 참고로하여 해당하는 인수($1....$7)만을 바꾸어 주면 원하는 필드정보만을 확인할 수 있을 것입니다.

 

'UNIX > Linux' 카테고리의 다른 글

[Linux] lastlog  (0) 2012.06.12
[Linux] last  (0) 2012.06.12
[Linux] halt  (0) 2012.06.12
[Linux] reboot  (0) 2012.06.12
[Linux] shutdown  (0) 2012.06.12
Posted by 몰라욧