ip 계산기라는 ipcalc 툴이 있다. 

$ sudo yum install ipcalc


mac에서도 설치 가능하다.

$ brew install ipcalc



ipcalc 확인

Usage: ipcalc [OPTION...]

  -c, --check         Validate IP address for specified address family

  -4, --ipv4          IPv4 address family (default)

  -6, --ipv6          IPv6 address family

  -b, --broadcast     Display calculated broadcast address

  -h, --hostname      Show hostname determined via DNS

  -m, --netmask       Display default netmask for IP (class A, B, or C)

  -n, --network       Display network address

  -p, --prefix        Display network prefix

  -s, --silent        Don't ever display error messages




브로드캐스트 주소 계산기

$  ipcalc -b 192.168.0.88/24

BROADCAST=192.168.0.255

$  ipcalc -b 192.168.0.88/25

BROADCAST=192.168.0.127



ip 확인하기

$ ipcalc -c 192.168.1.99

$ ipcalc -c 192.168.1.9999999999

ipcalc: bad IPv4 address: 192.168.1.9999999999


넷마스크 얻기

$ ipcalc -m 192.168.1.99

NETMASK=255.255.255.0



IP 네트워크 주소 확인하기

$ ipcalc -n 192.168.1.99/24

NETWORK=192.168.1.0

$ ipcalc -n 192.168.1.99/25

NETWORK=192.168.1.0

$ ipcalc -n 192.168.1.99/1

NETWORK=128.0.0.0





Posted by '김용환'
,


sudo echo 리디렉션을 해야 하는 상황이 종종 생긴다. 

이럴 때는 tee를 잘 사용한다.


$ sudo echo 10000 > /proc/sys/vm/vfs_cache_pressure

-bash: /proc/sys/vm/vfs_cache_pressure: 허가 거부



==>


$  echo 10000 | sudo tee --append /proc/sys/vm/vfs_cache_pressure

10000

'unix and linux' 카테고리의 다른 글

[리눅스] redir로 proxy 서버 만들기  (0) 2016.06.20
ipcalc - ip 계산기  (0) 2016.06.14
[pv] rpm으로 파이프 뷰 프로그램 설치 및 실행  (0) 2016.05.27
[python] carriage return 이슈  (0) 2016.05.27
dstat 툴  (0) 2016.05.23
Posted by '김용환'
,


pv 라는 파이프 뷰 프로그램이 있다. 얼마나 진행되는지 보여준다.

rpm 커맨드는 좀 더 상세하게 rpm 패키지가 어떻게 설치되었는지 정보를 확인할 수 있다.




$ pv a.out > /dev/null

8.46kiB 0:00:00 [10.8MiB/s] [========================================================================================================>] 100%


pv를 rpm으로 설치할 수 있다.




설치 


$ curl -O http://dl.fedoraproject.org/pub/epel/7/x86_64/p/pv-1.4.6-1.el7.x86_64.rpm

$ rpm -Uvh ~/pv-1.4.6-1.el7.x86_64.rpm




설치 확인


$ rpm -qa | grep "pv-"

pv-1.4.6-1.el7.x86_64




테스트 

$ dd if=/dev/urandom | pv | dd of=/dev/null



-qi는 정보 확인

$ rpm -qi pv

Name        : pv

Version     : 1.4.6

Release     : 1.el7

Architecture: x86_64

Install Date:

Group       : Development/Tools

Size        : 95481

License     : Artistic 2.0

Signature   : RSA/SHA256, 2014년 02월 05일 (수) 오후 01시 54분 31초, Key ID 6a2faea2352c64e5

Source RPM  : pv-1.4.6-1.el7.src.rpm

Build Date  :

Build Host  : buildvm-14.phx2.fedoraproject.org

Relocations : (not relocatable)

Packager    : Fedora Project

Vendor      : Fedora Project

URL         : http://www.ivarch.com/programs/pv.shtml

Summary     : A tool for monitoring the progress of data through a pipeline

Description :

PV ("Pipe Viewer") is a tool for monitoring the progress of data through a

pipeline.  It can be inserted into any normal pipeline between two processes

to give a visual indication of how quickly data is passing through, how long

it has taken, how near to completion it is, and an estimate of how long it

will be until completion.





설치된 디렉토리/파일 목록 확인

$ rpm -ql pv

/usr/bin/pv

/usr/share/doc/pv-1.4.6

/usr/share/doc/pv-1.4.6/COPYING

/usr/share/doc/pv-1.4.6/NEWS

/usr/share/doc/pv-1.4.6/README

/usr/share/doc/pv-1.4.6/TODO

/usr/share/locale/de/LC_MESSAGES/pv.mo

/usr/share/locale/fr/LC_MESSAGES/pv.mo

/usr/share/locale/pl/LC_MESSAGES/pv.mo

/usr/share/locale/pt/LC_MESSAGES/pv.mo

/usr/share/man/man1/pv.1.gz




설치된 디렉토리 확인

$ rpm -qd pv

/usr/share/doc/pv-1.4.6/COPYING

/usr/share/doc/pv-1.4.6/NEWS

/usr/share/doc/pv-1.4.6/README

/usr/share/doc/pv-1.4.6/TODO

/usr/share/man/man1/pv.1.gz




'unix and linux' 카테고리의 다른 글

ipcalc - ip 계산기  (0) 2016.06.14
sudo echo > 에러 대신 tee 커맨드  (0) 2016.06.07
[python] carriage return 이슈  (0) 2016.05.27
dstat 툴  (0) 2016.05.23
[centos7] systemctl 맛보기  (0) 2016.05.11
Posted by '김용환'
,



play 1.3.1은 carriage return 이슈가 있다. 


play를 실행하면, python 실행시 \r이 붙어 에러가 발생하고 실행이 되지 않는다.


/usr/local/play $ ./play

env: python\r: No such file or directory



carriage return이 있는지 간단하게 vi play 로 볼 수 있도 있지만, od 명령어를 사용하면, \r\n으로 release 한 것을 확인할 수 있다. 


$ cat play | od -c
0000000    #   !   /   u   s   r   /   b   i   n   /   e   n   v       p
0000020    y   t   h   o   n  \r  \n   #       ~   ~   ~   ~   ~   ~   ~
0000040    ~   ~   ~   ~   ~   ~   ~   ~   ~   ~   ~   ~   ~   ~   ~   ~


이 문제를 해결하려면, tr 명령어를 사용하여 \r를 모두 없앨 수 있다.


$ tr -d '\r' < play



$ play

동작..

'unix and linux' 카테고리의 다른 글

sudo echo > 에러 대신 tee 커맨드  (0) 2016.06.07
[pv] rpm으로 파이프 뷰 프로그램 설치 및 실행  (0) 2016.05.27
dstat 툴  (0) 2016.05.23
[centos7] systemctl 맛보기  (0) 2016.05.11
[centos 7] realpath 명령어  (0) 2016.05.03
Posted by '김용환'
,

dstat 툴

unix and linux 2016. 5. 23. 16:32



최근에 본 툴 중 마음에 드는 툴이다. 거의 모든 시스템 정보를  줄 단위로 볼 수 있다.


$yum install dstat


$ dstat --time --cpu --net --disk --sys --load --proc --top-cpu --mem --swap --tcp --udp



Posted by '김용환'
,

<systemctl로 서비스 예제>


먼저 httpd를 설치한다.

$ sudo yum install httpd
(참고로 예시로 사용할 crond는 이미 설치되어 있고 실행중인 데몬이다.)


systemctl 데몬 관련 커맨드

* systemctl start : 데몬 시작
* systemctl stop : 데몬 종료
* systemctl restart : 데몬 재시작
* systemctl reload : 데몬 reload (예, apache graceful )
* systemctl status : 데몬 상태 확인
* systemctl enable : 활성화 - 부팅 이후에도 계속 데몬을 실행할지 
* systemctl disable : 활성화 - 부팅 이후에도 계속 데몬을 실행안하도록
* systemctl is-enabled : 활성화인지 확인한다.
* systemctl is-active : 동작 중인지 확인한다.



예시

$ sudo systemctl start httpd.service

$ sudo systemctl status httpd.service
httpd.service - The Apache HTTP Server
   Loaded: loaded (/usr/lib/systemd/system/httpd.service; disabled)
   Active: active (running) since 수 2016-05-11 17:58:17 KST; 4s ago
     Docs: man:httpd(8)
           man:apachectl(8)
 Main PID: 11784 (httpd)
   Status: "Processing requests..."
   CGroup: /system.slice/httpd.service
           ├─11784 /usr/sbin/httpd -DFOREGROUND
           ├─11785 /usr/sbin/httpd -DFOREGROUND
           ├─11786 /usr/sbin/httpd -DFOREGROUND
           ├─11788 /usr/sbin/httpd -DFOREGROUND
           ├─11791 /usr/sbin/httpd -DFOREGROUND
           └─11792 /usr/sbin/httpd -DFOREGROUND

$ sudo systemctl enable httpd.service
ln -s '/usr/lib/systemd/system/httpd.service' '/etc/systemd/system/multi-user.target.wants/httpd.service'
$ sudo systemctl status httpd.service
httpd.service - The Apache HTTP Server
   Loaded: loaded (/usr/lib/systemd/system/httpd.service; enabled)
   Active: active (running) since 수 2016-05-11 17:58:17 KST; 21s ago
     Docs: man:httpd(8)
           man:apachectl(8)
 Main PID: 11784 (httpd)
   Status: "Total requests: 0; Current requests/sec: 0; Current traffic:   0 B/sec"
   CGroup: /system.slice/httpd.service
           ├─11784 /usr/sbin/httpd -DFOREGROUND
           ├─11785 /usr/sbin/httpd -DFOREGROUND
           ├─11786 /usr/sbin/httpd -DFOREGROUND
           ├─11788 /usr/sbin/httpd -DFOREGROUND
           ├─11791 /usr/sbin/httpd -DFOREGROUND
           └─11792 /usr/sbin/httpd -DFOREGROUND

$ sudo systemctl restart httpd.service
$ sudo systemctl status httpd.service
httpd.service - The Apache HTTP Server
   Loaded: loaded (/usr/lib/systemd/system/httpd.service; enabled)
   Active: active (running) since 수 2016-05-11 17:58:53 KST; 2s ago
     Docs: man:httpd(8)
           man:apachectl(8)
  Process: 11831 ExecStop=/bin/kill -WINCH ${MAINPID} (code=exited, status=0/SUCCESS)
 Main PID: 11836 (httpd)
   Status: "Processing requests..."
   CGroup: /system.slice/httpd.service
           ├─11836 /usr/sbin/httpd -DFOREGROUND
           ├─11837 /usr/sbin/httpd -DFOREGROUND
           ├─11838 /usr/sbin/httpd -DFOREGROUND
           ├─11839 /usr/sbin/httpd -DFOREGROUND
           ├─11840 /usr/sbin/httpd -DFOREGROUND
           └─11843 /usr/sbin/httpd -DFOREGROUND

$ sudo systemctl reload httpd.service
$ sudo systemctl status httpd.service
httpd.service - The Apache HTTP Server
   Loaded: loaded (/usr/lib/systemd/system/httpd.service; enabled)
   Active: active (running) since 수 2016-05-11 17:58:53 KST; 20s ago
     Docs: man:httpd(8)
           man:apachectl(8)
  Process: 11831 ExecStop=/bin/kill -WINCH ${MAINPID} (code=exited, status=0/SUCCESS)
  Process: 11859 ExecReload=/usr/sbin/httpd $OPTIONS -k graceful (code=exited, status=0/SUCCESS)
 Main PID: 11836 (httpd)
   Status: "Total requests: 0; Current requests/sec: 0; Current traffic:   0 B/sec"
   CGroup: /system.slice/httpd.service
           ├─11836 /usr/sbin/httpd -DFOREGROUND
           ├─11860 /usr/sbin/httpd -DFOREGROUND
           ├─11861 /usr/sbin/httpd -DFOREGROUND
           ├─11862 /usr/sbin/httpd -DFOREGROUND
           ├─11863 /usr/sbin/httpd -DFOREGROUND
           └─11864 /usr/sbin/httpd -DFOREGROUND

$ sudo systemctl stop httpd.service
$ sudo systemctl status httpd.service
httpd.service - The Apache HTTP Server
   Loaded: loaded (/usr/lib/systemd/system/httpd.service; enabled)
   Active: inactive (dead) since 수 2016-05-11 17:59:22 KST; 1s ago
     Docs: man:httpd(8)
           man:apachectl(8)
  Process: 11883 ExecStop=/bin/kill -WINCH ${MAINPID} (code=exited, status=0/SUCCESS)
  Process: 11859 ExecReload=/usr/sbin/httpd $OPTIONS -k graceful (code=exited, status=0/SUCCESS)
  Process: 11836 ExecStart=/usr/sbin/httpd $OPTIONS -DFOREGROUND (code=exited, status=0/SUCCESS)
 Main PID: 11836 (code=exited, status=0/SUCCESS)
   Status: "Total requests: 0; Current requests/sec: 0; Current traffic:   0 B/sec"

$ sudo systemctl disable httpd.service
rm '/etc/systemd/system/multi-user.target.wants/httpd.service'

$  systemctl is-enabled httpd.service

disabled

$  systemctl is-active httpd.service

unknown

$  systemctl is-active crond.service

inactive

$  systemctl is-enabled crond.service

enabled





서비스 설정 파일 확인하기


$ ls -al /usr/lib/systemd/system/httpd.service

-rw-r--r-- 1 root root 752 11월 20 06:35 /usr/lib/systemd/system/httpd.service

ls -al /usr/lib/systemd/system/crond.service

-rw-r--r--. 1 root root 284  7월 31  2014 /usr/lib/systemd/system/crond.service







<systemctl 커맨드 맛보기>


서비스 타입중 현재 실행중인 시스템 서비스 목록 보기


$ systemctl -t service -a --state running

UNIT                              LOAD   ACTIVE SUB     DESCRIPTION

proc-sys-fs-binfmt_misc.automount loaded active running Arbitrary Executable File Formats File System Automount Point

session-30.scope                  loaded active running Session 30 of user deploy

acpid.service                     loaded active running ACPI Event Daemon

auditd.service                    loaded active running Security Auditing Service

dbus.service                      loaded active running D-Bus System Message Bus

getty@tty1.service                loaded active running Getty on tty1

irqbalance.service                loaded active running irqbalance daemon

network.service                   loaded active running LSB: Bring up/down networking

ntpd.service                      loaded active running Network Time Service

rsyncd.service                    loaded active running fast remote file copy program daemon

rsyslog.service                   loaded active running System Logging Service

snmpd.service                     loaded active running Simple Network Management Protocol (SNMP) Daemon.

sshd.service                      loaded active running OpenSSH server daemon

systemd-journald.service          loaded active running Journal Service

systemd-logind.service            loaded active running Login Service

systemd-udevd.service             loaded active running udev Kernel Device Manager

dbus.socket                       loaded active running D-Bus System Message Bus Socket

systemd-journald.socket           loaded active running Journal Socket

systemd-udevd-control.socket      loaded active running udev Control Socket

systemd-udevd-kernel.socket       loaded active running udev Kernel Socket


LOAD   = Reflects whether the unit definition was properly loaded.

ACTIVE = The high-level unit activation state, i.e. generalization of SUB.

SUB    = The low-level unit activation state, values depend on unit type.


20 loaded units listed.

To show all installed unit files use 'systemctl list-unit-files'.



시스템의 모든 서비스의 간단한 모든 상태 정보를 보고 싶다면, 다음을 사용한다. 


$ systemctl --type service --all


UNIT                                  LOAD   ACTIVE   SUB     DESCRIPTION

acpid.service                         loaded active   running ACPI Event Daemon

auditd.service                        loaded active   running Security Auditing Service

brandbot.service                      loaded inactive dead    Flexible Branding Service

cloud-config.service                  loaded active   exited  Apply the settings specified in cloud-config

cloud-final.service                   loaded active   exited  Execute cloud user/final scripts

cloud-init-local.service              loaded active   exited  Initial cloud-init job (pre-networking)

cloud-init.service                    loaded active   exited  Initial cloud-init job (metadata service crawler)

crond.service                         loaded inactive dead    Command Scheduler

dbus.service                          loaded active   running D-Bus System Message Bus

display-manager.service               not-found inactive dead    display-manager.service

dracut-shutdown.service               loaded inactive dead    Restore /run/initramfs

emergency.service                     loaded inactive dead    Emergency Shell

exim.service                          not-found inactive dead    exim.service

getty@tty1.service                    loaded active   running Getty on tty1

ip6tables.service                     not-found inactive dead    ip6tables.service

iptables.service                      not-found inactive dead    iptables.service




유닛 파일 타입의 systemctl로 사용할 수 있는 시스템 서비스 목록을 본다.



$ systemctl list-unit-files

UNIT FILE                              STATE

proc-sys-fs-binfmt_misc.automount      static

dev-hugepages.mount                    static

dev-mqueue.mount                       static

proc-sys-fs-binfmt_misc.mount          static

sys-fs-fuse-connections.mount          static

sys-kernel-config.mount                static

sys-kernel-debug.mount                 static

tmp.mount                              disabled

brandbot.path                          disabled

systemd-ask-password-console.path      static

systemd-ask-password-plymouth.path     static

systemd-ask-password-wall.path         static

session-2.scope                        static

session-29.scope                       static

session-30.scope                       static

session-9.scope                        static

acpid.service                          enabled

arp-ethers.service                     disabled

atd.service                            disabled

auditd.service                         enabled

autovt@.service                        disabled

brandbot.service                       static

cloud-config.service                   enabled

cloud-final.service                    enabled

cloud-init-local.service               enabled

cloud-init.service                     enabled

...



리스닝하는 소켓 타입의 systemctl로 사용할 수 있는 시스템 서비스 목록을 본다.


$ systemctl list-sockets

LISTEN                          UNIT                         ACTIVATES

/dev/initctl                    systemd-initctl.socket       systemd-initctl.service

/dev/log                        systemd-journald.socket      systemd-journald.service

/run/systemd/journal/socket     systemd-journald.socket      systemd-journald.service

/run/systemd/journal/stdout     systemd-journald.socket      systemd-journald.service

/run/systemd/shutdownd          systemd-shutdownd.socket     systemd-shutdownd.service

/run/udev/control               systemd-udevd-control.socket systemd-udevd.service

/var/run/dbus/system_bus_socket dbus.socket                  dbus.service

kobject-uevent 1                systemd-udevd-kernel.socket  systemd-udevd.service


8 sockets listed.

Pass --all to see loaded but inactive sockets, too.




사용할 수 있는 모든 유닛 타입은 다음과 같다.


$ systemctl -t help

Available unit types:

service

socket

target

device

mount

automount

snapshot

timer

swap

path

slice

scope



특정 서비스의 dependency 유닛을 보려면 다음과 같은 커맨드를 사용한다.



$ systemctl list-dependencies crond.service

crond.service

├─system.slice

└─basic.target

  ├─microcode.service

  ├─rhel-autorelabel-mark.service

  ├─rhel-autorelabel.service

  ├─rhel-configure.service

  ├─rhel-dmesg.service

  ├─rhel-loadmodules.service

  ├─paths.target

  ├─slices.target

  │ ├─-.slice

  │ └─system.slice

  ├─sockets.target

  │ ├─dbus.socket

  │ ├─rsyncd.socket

  │ ├─systemd-initctl.socket

  │ ├─systemd-journald.socket

  │ ├─systemd-shutdownd.socket

  │ ├─systemd-udevd-control.socket

  │ └─systemd-udevd-kernel.socket

  ├─sysinit.target

  │ ├─dev-hugepages.mount

  │ ├─dev-mqueue.mount

  │ ├─kmod-static-nodes.service

  │ ├─plymouth-read-write.service

  │ ├─plymouth-start.service

  │ ├─proc-sys-fs-binfmt_misc.automount

  │ ├─sys-fs-fuse-connections.mount

  │ ├─sys-kernel-config.mount

  │ ├─sys-kernel-debug.mount

  │ ├─systemd-ask-password-console.path

  │ ├─systemd-binfmt.service

  │ ├─systemd-journal-flush.service

  │ ├─systemd-journald.service

  │ ├─systemd-modules-load.service

  │ ├─systemd-random-seed.service

  │ ├─systemd-sysctl.service

  │ ├─systemd-tmpfiles-setup-dev.service

  │ ├─systemd-tmpfiles-setup.service

  │ ├─systemd-udev-trigger.service

  │ ├─systemd-udevd.service

  │ ├─systemd-update-utmp.service

  │ ├─systemd-vconsole-setup.service

  │ ├─cryptsetup.target

  │ ├─local-fs.target

  │ │ ├─-.mount

  │ │ ├─rhel-import-state.service

  │ │ ├─rhel-readonly.service

  │ │ ├─systemd-fsck-root.service

  │ │ └─systemd-remount-fs.service

  │ └─swap.target

  │   └─swap-swapfile1.swap

  └─timers.target

    └─systemd-tmpfiles-clean.timer





'unix and linux' 카테고리의 다른 글

[python] carriage return 이슈  (0) 2016.05.27
dstat 툴  (0) 2016.05.23
[centos 7] realpath 명령어  (0) 2016.05.03
센트OS 7 다운로드 URL 설명  (0) 2016.05.02
setuid 동작 결과를 ps로 확인하기(ruser, euser)  (0) 2016.04.28
Posted by '김용환'
,



realpath 명령어는 centos7부터 내장된 명령어로서 파일의 절대 위치를 알려준다. 

특히 심볼링 링크가 가르키는 디렉토리를 보고 싶을 때 확인할 수 있다. 



centos 7부터 /bin 디렉토리가 /usr/bin/으로 이동했다.


$ ls -l /bin

lrwxrwxrwx. 1 root root 7  7월 28  2015 /bin -> usr/bin



$ realpath /bin

/usr/bin






'unix and linux' 카테고리의 다른 글

dstat 툴  (0) 2016.05.23
[centos7] systemctl 맛보기  (0) 2016.05.11
센트OS 7 다운로드 URL 설명  (0) 2016.05.02
setuid 동작 결과를 ps로 확인하기(ruser, euser)  (0) 2016.04.28
[nginx] echo > sudo 파일 권한  (0) 2016.04.25
Posted by '김용환'
,


센트OS 를 버전별로 다운받을 수 있는 사이트이다.

http://centos.mirror.cdnetworks.com/



2016년 5월 현재, 다음과 같은 센트OS 7를 다운받을 수 있다. 





7.x.yyyy 형태를 가지고 있는데, 7.x는 버전을 의미하고, yyyy는 연과 월단위로 표현한다.

7.2.1511은 센트OS 7.2이고, 15년 11월에 출시도었음을 의미한다.



센트OS는 x86의 64비트만 지원하기 때문에 x86_64 버전만 다운받을 수 있다 .


http://centos.mirror.cdnetworks.com/7.2.1511/ 를 보면, cloud,iso등과 같은 형태로 배포된다.



작은 규모의(minimal) iso를 다운받으려면, 브라우져에 다음 url을 접속하고, 

http://centos.mirror.cdnetworks.com/7.2.1511/isos/x86_64/


아래 링크를 클릭해서 다운받는다.


정상적인 파일인지 확인하기 위해서 md5로 체크섬을 확인한다.



$ md5 CentOS-7-x86_64-Minimal-1511.iso

MD5 (CentOS-7-x86_64-Minimal-1511.iso) = 88c0437f0a14c6e2c94426df9d43cd67



$ cat md5sum.txt

c875b0f1dabda14f00a3e261d241f63e  CentOS-7-x86_64-DVD-1511.iso

dba29c59117400b111633be2bf2aaf0e  CentOS-7-x86_64-Everything-1511.iso

7e46208ba6c5fe817a3ce981aa122f54  CentOS-7-x86_64-LiveGNOME-1511.iso

d9f8e2ae2148d0abdf55a2a9eef42f00  CentOS-7-x86_64-LiveKDE-1511.iso

88c0437f0a14c6e2c94426df9d43cd67  CentOS-7-x86_64-Minimal-1511.iso

99d305fa40ec9e28ef8450c3bcc45f85  CentOS-7-x86_64-NetInstall-1511.iso




md5sum.txt의 값과 md5의 값이 같으면 문제없다는 뜻이다.


Posted by '김용환'
,



http://theurbanpenguin.com/wp/index.php/using-a-simple-c-program-to-explain-the-suid-permission/ 의 소스를 참조했다.



$ cat > test.c

#include <stdio.h>

#include <unistd.h>

int main () {

  int real = getuid();

  int euid = geteuid();

  printf("The REAL UID =: %d\n", real);

  printf("The EFFECTIVE UID =: %d\n", euid);

  sleep(100);

}



$ cc test.c

$ ./a.out

The REAL UID =: 1000

The EFFECTIVE UID =: 1000



$ sudo chown root a.out

$ sudo chmod 4755 a.out



결과

$ ./a.out

The REAL UID =: 1000

The EFFECTIVE UID =: 0

(대기)



다른 터미널에서 ps 명령어로 확인한다.

$ ps -eo pid,euser,ruser,comm | grep a.out
PID EUSER    RUSER    COMMAND

 4481 root     deploy   a.out



리눅스에서 프로세스의 유효한(effective) 사용자 ID(euid)와 리얼(real) 사용자 ID(ruid)를 볼 수 있다.

setuid를 실행하는 시점에서는 다른 리얼 사용자 ID를 볼 수 있도록 아래 명령어를 실행한다. 일반적인 경우 한 프로세스의 euid와 ruid는 동일하다.


a.out 은 setuid로 실행되기 때문에 결과가 euser와 ruser가 다른 값이 나온다.

Posted by '김용환'
,


sudo 를 사용해야 root권한을 얻는 리눅스 시스템에서 자주 실수할 수 있는 명령어이다.



echo를 이용하여 특정 파일에 리다이렉트하여 파일을 만드는 작업을 할 때. 

root 권한이 없어서 에러가 발생한다.


sudo echo "set \$l7 ${COMMAND};" > /usr/local/nginx/conf/nginx-test.conf"



이런 경우는 파이프라인을 사용하여 tee를 이용할 수 있다. 


echo "set \$l7 ${COMMAND};" | sudo tee /usr/local/nginx/conf/nginx-test.conf"



파일에 내용을 추가를 하고 싶다면, tee -a 를 사용한다.


echo "set \$l7 ${COMMAND};" | sudo tee -a /usr/local/nginx/conf/nginx-test.conf"




Posted by '김용환'
,