brunch

You can make anything
by writing

C.S.Lewis

by Master Seo Jul 24. 2019

16. 리눅스 마스터 문제 - 명령어1


<1> 리눅스를 배우는 목적

<2> 구성도

<3> 리눅스 서버  로그인

<4> 리눅스 명령어들



<1> 리눅스를 배우는 목적

개임이나 서비스를 만들어 올리려 한다.



<2>  구성도


Smart Phone -----------  Linux Server


기본적으로 리눅스 서버를 다를줄 알아야 한다.

서버에 명령을 내릴수 있어야 한다.

서버에  홈페이지도 만들수 있다

서버에 소프트웨어 올려 게임도 만들수 있다.



<3> 리눅스 서버  로그인


Puttty 프로그램  https://www.chiark.greenend.org.uk/~sgtatham/putty/latest.html

접속 키


서버1 IP  :

서버2 IP  :




<4> 리눅스 명령어들


<명령어1>


root 로  변경

# sudo su -



ls가 어디 있는지 찾는 명령어  which
[root@ip-172-31-33-57 ~]# which ls
alias ls='ls --color=auto'
/bin/ls


별명을 만드는 명령어  alias

[root@ip-172-31-33-57 ~]# clear


[root@ip-172-31-33-57 ~]# alias c=clear
[root@ip-172-31-33-57 ~]#


[root@ip-172-31-33-57 ~]# alias F='ls -al'
[root@ip-172-31-33-57 ~]# F

total 32
dr-xr-x--- 3 root root 4096 Jul 24 01:10 .
dr-xr-xr-x 25 root root 4096 Jul 24 01:10 ..
-rw-r--r-- 1 root root 18 Jan 15 2011 .bash_logout


별명을 만든것을 제거 하는 명령어   unalias

[root@ip-172-31-33-57 ~]# unalias F
[root@ip-172-31-33-57 ~]# F

-bash: F: command not found


메뉴얼 위치 찾는 명령어  whereis

[root@ip-172-31-33-57 ~]# whereis  ls

ls: /bin/ls /usr/share/man/man1p/ls.1p.gz /usr/share/man/man1/ls.1.gz
[root@ip-172-31-33-57 ~]# whereis  find
find: /usr/bin/find /bin/find /usr/share/man/man1p/find.1p.gz /usr/share/man/man1/find.1.gz


경로를 추가해주는 명령어  export PATH=$PATH

[root@ip-172-31-33-57 ~]# export PATH=$PATH:/usr/bin


info는 GNU에서 제공하는 온라인 메뉴얼 명령어이다.

[root@ip-172-31-33-57 ~]# info


계정을 만드는 명령어  useradd   

5일동안만 사용하도록 하는것  -f

[root@ip-172-31-33-57 ~]# useradd  -f  5  aws111
[ec2-user@ip-172-31-89-166 ~]$ sudo su -

[root@ip-172-31-89-166 ~]#exit


[root@ip-172-31-89-166 ~]# useradd -f 5 aws111

[root@ip-172-31-89-166 ~]# more    /etc/passwd


[root@ip-172-31-89-166 ~]# su - aws111

[aws111@ip-172-31-89-166 ~]$ pwd

/home/aws111



useradd

userdel

usermod

usercreate   < ------ 아니다.



유저 생성과 삭제
useradd
userdel
adduser

deluser  < -  deluser 은 없다.


계정 암호 변경하기

 # passwd   aws111

[root@ip-172-31-33-57 ~]# passwd aws111
Changing password for user aws111
New password:

[root@ip-172-31-33-57 ~]# more /etc/passwd
aws111:x:501:501::/home/aws111:/bin/bash



사용자 추가하기 useradd

[root@ip-172-31-89-166 ~]# useradd aws222

[root@ip-172-31-89-166 ~]# su - aws222

[aws222@ip-172-31-89-166 ~]$ pwd

/home/aws222

[aws222@ip-172-31-89-166 ~]$



passwd 파일로  계정, 홈 디렉토리를 볼수 있다.

[root@ip-172-31-89-166 ~]# more /etc/passwd

aws222:x:1002:1002::/home/aws222:/bin/bash



암호화된  v정보 파일  shadow

[root@ip-172-31-33-57 ~]# cat    /etc/shadow
root:*LOCK*:14600::::::
bin:*:16323:0:99999:7:::
daemon:*:16323:0:99999:7:::


계정

그룹 ?


그룹을 생성하는 명령어  groupadd  -g

[root@ip-172-31-33-57 ~]# groupadd
Usage: groupadd [options] GROUP

Options:
-g, --gid GID use GID for the new group



그룹을 변경하는 명령어   groupadd  -n

[root@ip-172-31-33-57 ~]# groupmod
Usage: groupmod [options] GROUP

Options:
-n, --new-name NEW_GROUP change the name to NEW_GROUP




<명령어2>



파일과 디렉토리 관련명령어
[root@ip-172-31-33-57 ~]# ls
[root@ip-172-31-33-57 ~]# cd   (홈 디렉토리로 가는 명령어)
[root@ip-172-31-33-57 ~]# ls -al
total 36
dr-xr-x--- 3 root root 4096 Jul 24 01:51 .
dr-xr-xr-x 25 root root 4096 Jul 24 01:10 ..
-rw------- 1 root root 5 Jul 24 01:51 .bash_history
-rw-r--r-- 1 root root 18 Jan 15 2011 .bash_logout
-rw-r--r-- 1 root root 176 Jan 15 2011 .bash_profile
-rw-r--r-- 1 root root 176 Jan 15 2011 .bashrc
-rw-r--r-- 1 root root 100 Jan 15 2011 .cshrc
drwx------ 2 root root 4096 Jul 24 01:10 .ssh
-rw-r--r-- 1 root root 129 Jan 15 2011 .tcshrc


데몬으르 확인하는 명령어 PS

소프트웨어가 돌아가고 있는지 확인하는 명령어.

[root@ip-172-31-33-57 ~]# ps -ef
UID PID PPID C STIME TTY TIME CMD
root 1 0 0 01:10 ? 00:00:01 /sbin/init
root 2 0 0 01:10 ? 00:00:00 [kthreadd]



현재  작업중인 디렉토리를  확인하는 명령어

[root@ip-172-31-33-57 var]# pwd
/var



cd ..  의 의미는 ?

[root@ip-172-31-33-57 home]# mkdir 111
[root@ip-172-31-33-57 home]# cd 111
[root@ip-172-31-33-57 111]# pwd
/home/111

[root@ip-172-31-33-57 111]# mkdir 222
[root@ip-172-31-33-57 111]# cd 222
[root@ip-172-31-33-57 222]# pwd
/home/111/222
[root@ip-172-31-33-57 222]# cd ..
[root@ip-172-31-33-57 111]# pwd
/home/111



부모  디렉토리까지 같이 만드는 옵션 mkdir  -p


[root@ip-172-31-89-166 ~]# mkdir -p 333/444

[root@ip-172-31-89-166 ~]# pwd

/root

[root@ip-172-31-89-166 ~]# ls

222  333  anaconda-ks.cfg  original-ks.cfg

[root@ip-172-31-89-166 ~]# cd 333

[root@ip-172-31-89-166 333]# ls

444

[root@ip-172-31-89-166 333]# cd 444

[root@ip-172-31-89-166 444]# ls

[root@ip-172-31-89-166 444]# pwd

/root/333/444



인덱스를 보는 명령어  , ls 의 옵션  -i

인덱스. 대표 정보.표시.

ls   -i  


[root@ip-172-31-33-57 ~]# ls
122 222
[root@ip-172-31-33-57 ~]# ls -i
276229 122 276230 222


[root@ip-172-31-89-166 444]# touch a

[root@ip-172-31-89-166 444]# touch b

[root@ip-172-31-89-166 444]# touch c

[root@ip-172-31-89-166 444]# touch d

[root@ip-172-31-89-166 444]#

[root@ip-172-31-89-166 444]# ls

a  b  c  d


ls   -r 옵션의 의미는 ?
[root@ip-172-31-89-166 444]# ls -r

d  c  b  a



cp 는 ?   복사.  카피

cp  -r  의미는 ?  

디렉토리 복사하는 명령어.

[root@ip-172-31-89-166 444]# cp ddddddd eee

cp: -r not specified; omitting directory 'ddddddd'

[root@ip-172-31-89-166 444]# cp -r ddddddd eee

[root@ip-172-31-89-166 444]# ls

a  aaa  aaaa  b  c  d  ddddddd  eee

[root@ip-172-31-89-166 444]# ls -al

total 0

drwxr-xr-x. 4 root root 91 Jul 28 06:07 .

drwxr-xr-x. 3 root root 17 Jul 28 05:59 ..

-rw-r--r--. 1 root root  0 Jul 28 06:04 a

-rw-r--r--. 1 root root  0 Jul 28 06:06 aaa

-rw-r--r--. 1 root root  0 Jul 28 06:06 aaaa

-rw-r--r--. 1 root root  0 Jul 28 06:04 b

-rw-r--r--. 1 root root  0 Jul 28 06:04 c

-rw-r--r--. 1 root root  0 Jul 28 06:04 d

drwxr-xr-x. 2 root root  6 Jul 28 06:07 ddddddd

drwxr-xr-x. 2 root root  6 Jul 28 06:07 eee

[root@ip-172-31-89-166 444]#



rm ?  


remove , 파일 삭제하는 명령어.

-i   옵션은 ? 물어보고 삭제하는 옵션.


rm 의 질문 형식 옵션은 ??
[root@ip-172-31-33-57 ~]# rm   -i  a
rm: remove regular empty file ‘a’?  n



파일  변경하기  mv


[root@ip-172-31-89-166 444]# mv a f

[root@ip-172-31-89-166 444]# ls

aaa  aaaa  b  c  d  ddddddd  eee  f

[root@ip-172-31-89-166 444]#



[root@ip-172-31-33-57 ~]# touch --help
-a change only the access time
access

-m change only the modification time
modify

파일변경 시간은 불변이다.  

change를 할수 없다.



[root@ip-172-31-33-57 ~]# file a
a: empty


file -i 는 정보를 보여준다.  케릭터셋에 파일의 정보를 보여준다.(바이너리 또는 text 등)
[root@ip-172-31-33-57 ~]# file -i a
a: inode/x-empty; charset=binary

# find   /etc    -name   '*.conf'  2> /dev/null
2는 오류이다.


# find  /    - name   ls    2 > /dev/null




웹서버 띠우기
yum  install  httpd  -y

/usr/sbin/httpd


find / -name httpd.conf

[root@ip-172-31-33-57 ~]# find / -name httpd.conf
/etc/httpd/conf/httpd.conf
[root@ip-172-31-33-57 ~]# cd /etc/httpd/conf
[root@ip-172-31-33-57 conf]# more httpd.conf
#
# This is the main Apache server configuration file. It contains the
# configuration directives that give the server its instructions.


[root@ip-172-31-89-166 html]# cd /var/www/html

[root@ip-172-31-89-166 html]# vi index.html


파일 내용 보는 명령어를
tail httpd.conf
head httpd.conf
more  httpd.conf



파일의 마지막 내용을 계속 모니터링 하는 tail옵션  -f
[root@ip-172-31-33-57 conf]# tail   -f   /var/log/messages
Jul 24 04:35:14 ip-172-31-33-57 dhclient[2101]: bound to 172.31.33.57 -- renewal in 1684 seconds.
Jul 24 04:35:14 ip-172-31-33-57 ec2net: [get_meta] Trying to get http://169.254.169.254/latest/meta-data/network/interfaces/macs/0a:e9:4b:65:25:68/local-ipv4s
Jul 24 04:35:14 ip-172-31-33-57 ec2net: [rewrite_aliases] Rewriting aliases of eth0



|  more는 한페이지씩  보여주라는것이다.

[root@ip-172-31-33-57 etc]# ls -al | more
total 1400
drwxr-xr-x 79 root root 4096 Jul 24 04:45 .
dr-xr-xr-x 25 root root 4096 Jul 24 01:10 ..



>  는 파일로 만들라는 것이다.

[root@ip-172-31-89-166 etc]# cd /etc

[root@ip-172-31-89-166 etc]# ls

[root@ip-172-31-33-57 etc]# ls  > sss
[root@ip-172-31-33-57 etc]# ls  sss
-rw-r--r-- 1 root root 10486 Jul 24 04:46 sss
[root@ip-172-31-33-57 etc]#more sss



> 는 출력하라는 것이다.  파일로 만들어 주라!

>>  는 추가이다.

<  는 입력하라는 것이다.

[root@ip-172-31-89-166 ~]# more a >> b

[root@ip-172-31-89-166 ~]# more a

aaaa

[root@ip-172-31-89-166 ~]# more b

bbbb

aaaa

[root@ip-172-31-89-166 ~]#



cat   /etc/passwd   | grep  aws111

/etc/passwd파일을 읽어서  ,  aws111이 있으면 찾아줘라.


[root@ip-172-31-89-166 ~]# more /etc/passwd | grep aws111

aws111:x:1001:1001::/home/aws111:/bin/bash



grep에  -v  욥션은  제외이다.

cat /etc/passwd |grep -v aws111



cat /etc/passwd |grep -v ec2

1,3  은   2번째와 네번째는 보여주세요.

etc]# cut  -d: -f  1,3  /etc/shadow

1- 10 연속 된 리스트



cmp는 비교해 틀린  라인 줄만 보여준다.

[root@ip-172-31-89-166 ~]# more a

aaaa

[root@ip-172-31-89-166 ~]# more b

bbbb

aaaa

[root@ip-172-31-89-166 ~]# cmp a b

a b differ: byte 1, line 1



파이프라인 ( | )  은 여러개가 가능하다.

[root@ip-172-31-33-57 ~]# ls -al | more | diff a b
3,4c3
< 3
< 4
---
>



stty

유용한 키 (Ctrl + C 등) 를 설정하는  명령어




<명령어 >


사용자  파일을  찾는것.


[root@ip-172-31-33-57 ~]# find /home -user aws123123
/home/aws123123
/home/aws123123/.bash_logout
/home/aws123123/.bashrc
/home/aws123123/.bash_profile



[root@ip-172-31-33-57 ~]# find /home -user ec2-user
/home/ec2-user
/home/ec2-user/.ssh
/home/ec2-user/.ssh/authorized_keys
/home/ec2-user/.bash_history
/home/ec2-user/.bash_logout
/home/ec2-user/.bashrc
/home/ec2-user/.bash_profile
[root@ip-172-31-33-57 ~]#



서버 셧다운

-r은  재시작

-h 는 중지

+30분 : 30분 후



[root@ip-172-31-33-57 ~]# shutdown --help
Usage: shutdown [OPTION]... TIME [MESSAGE]
Bring the system down.

Options:
-r reboot after shutdown
-h halt or power off after shutdown



[root@ip-172-31-33-57 ~]# date
Wed Jul 24 05:21:06 UTC 2019


[root@ip-172-31-33-57 ~]# time
real 0m0.000s
user 0m0.000s
sys 0m0.000s


hostname 은  이름을 알아보는것이다.

도메인 네임


[root@ip-172-31-33-57 ~]# hostname
ip-172-31-33-57



[root@ip-172-31-33-57 ~]# ifconfig
eth0 Link encap:Ethernet HWaddr 0A:E9:4B:65:25:68
inet addr:172.31.33.57 Bcast:172.31.47.255 Mask:255.255.240.0
inet6 addr: fe80::8e9:4bff:fe65:2568/64 Scope:Link
UP BROADCAST RUNNING MULTICAST MTU:9001 Metric:1
RX packets:13817 errors:0 dropped:0 overruns:0 frame:0
TX packets:6428 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:10061238 (9.5 MiB) TX bytes:882090 (861.4 KiB)

lo Link encap:Local Loopback
inet addr:127.0.0.1 Mask:255.0.0.0
inet6 addr: ::1/128 Scope:Host
UP LOOPBACK RUNNING MTU:65536 Metric:1
RX packets:2 errors:0 dropped:0 overruns:0 frame:0
TX packets:2 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:140 (140.0 b) TX bytes:140 (140.0 b)


[root@ip-172-31-33-57 ~]# ping 1.1.1.1
PING 1.1.1.1 (1.1.1.1) 56(84) bytes of data.
64 bytes from 1.1.1.1: icmp_seq=1 ttl=48 time=31.6 ms
^C
--- 1.1.1.1 ping statistics ---
1 packets transmitted, 1 received, 0% packet loss, time 0ms
rtt min/avg/max/mdev = 31.661/31.661/31.661/0.000 ms
[root@ip-172-31-33-57 ~]#




traceroute  는 경로를 찾아 가는것이다.


[root@ip-172-31-33-57 ~]# traceroute www.naver.com
traceroute to www.naver.com (210.89.164.90), 30 hops max, 60 byte packets
1 ec2-52-79-0-22.ap-northeast-2.compute.amazonaws.com (52.79.0.22) 25.008 ms ec2-52-79-0-26.ap-northeast-2.compute.amazonaws.com (52.79.0.26) 6.931 ms 6.929 ms
2 100.64.3.12 (100.64.3.12) 18.586 ms 100.64.1.72 (100.64.1.72) 18.412 ms 100.64.1.202 (100.64.1.202) 12.570 ms
3 100.64.3.3 (100.64.3.3) 20.022 ms 100.64.2.5 (100.64.2.5) 15.060 ms 100.64.1.5 (100.64.1.5) 15.044 ms
4 100.64.17.165 (100.64.17.165) 0.611 ms 100.64.16.165 (100.64.16.165) 0.624 ms 100.64.17.69 (100.64.17.69) 0.5




[root@ip-172-31-33-57 ~]# dig www.naver.com mx

; <<>> DiG 9.8.2rc1-RedHat-9.8.2-0.68.rc1.59.amzn1 <<>> www.naver.com mx
;; global options: +cmd
;; Got answer:
;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 37627
;; flags: qr rd ra; QUERY: 1, ANSWER: 1, AUTHORITY: 1, ADDITIONAL: 0

;; QUESTION SECTION:
;www.naver.com. IN MX


[root@ip-172-31-33-57 ~]# dig www.daum.net +short
www.g.daum.net.
203.133.167.16
211.231.99.80
[root@ip-172-31-33-57 ~]#


[root@ip-172-31-33-57 ~]# dig www.facebook.com +short
star-mini.c10r.facebook.com.
31.13.82.36
[root@ip-172-31-33-57 ~]# dig www.facebook.com mx +short
star-mini.c10r.facebook.com.
[root@ip-172-31-33-57 ~]#




<명령어3>


소유권 변경 명령어  chown

오너를 변경한다.


chown  :dev    aaa.txt



aaa 디렉토리 아래  파일의   소유자를 seo로 변경하는 명령어.

chown  -R  seo   /home/aaa



chgrp  그룹 소유권을 변경하는 명령어.

chgrp  seo2   aaa.txt


그룹 쇼유가 seo2로 변경된다.



chgrp 옵션중

하위까지 그룹 소유권 과  하위 모든 소유권을 변경하는옵션

-R



ls  -al

에서  srw-r-w  에서 s의 의미는?



[root@ip-172-31-33-57 ~]# ls -al
total 60
dr-xr-x--- 5 root root 4096 Jul 24 05:07 .
dr-xr-xr-x 25 root root 4096 Jul 24 01:10 ..
-rw-r--r-- 1 root root 0 Jul 24 04:12 122
-rw-r--r-- 1 root root 0 Jul 24 04:12 222
-rw-r--r-- 1 root root 8 Jul 24 05:00 a
-rw-r--r-- 1 root root 5 Jul 24 04:59 b
-rw------- 1 root root 647 Jul 24 04:26 .bash_history
-rw-r--r-- 1 root root 18 Jan 15 2011 .bash_logout
-rw-r--r-- 1 root root 176 Jan 15 2011 .bash_profile
-rw-r--r-- 1 root root 176 Jan 15 2011 .bashrc
-rw-r--r-- 1 root root 13 Jul 24 05:07 c
-rw-r--r-- 1 root root 100 Jan 15 2011 .cshrc
-rw-r--r-- 1 root root 33 Jul 24 05:07 d
drwxr-xr-x 2 root root 4096 Jul 24 04:22 dir1
drwxr-xr-x 2 root root 4096 Jul 24 04:23 kkk
drwx------ 2 root root 4096 Jul 24 01:10 .ssh
-rw-r--r-- 1 root root 129 Jan 15 2011 .tcshrc
[root@ip-172-31-33-57 ~]#

s의 의미는 소켓




ls -al 에서


r 는 읽기

w는 쓰기

x는 실행

-는 생성,삭제등 못하는것.






파일에 대한  허가권 변경.  chmod

파일에 대해  읽기, 쓰기, 실행 권한을 변경한다.


[root@ip-172-31-33-57 ~]# ls -al
total 60
dr-xr-x--- 5 root root 4096 Jul 24 05:07 .
dr-xr-xr-x 25 root root 4096 Jul 24 01:10 ..
-rw-r--r-- 1 root root 0 Jul 24 04:12 122
-rw-r--r-- 1 root root 0 Jul 24 04:12 222
-rw-r--r-- 1 root root 8 Jul 24 05:00 a


[root@ip-172-31-33-57 ~]# chmod 400 a


[root@ip-172-31-33-57 ~]# ls -al a
-r-------- 1 root root 8 Jul 24 05:00 a



[root@ip-172-31-33-57 ~]# ls -al a
-r-------- 1 root root 8 Jul 24 05:00 a


[root@ip-172-31-33-57 ~]# chmod 755 a


[root@ip-172-31-33-57 ~]# ls -al a
-rwxr-xr-x 1 root root 8 Jul 24 05:00 a


7은  읽기  쓰기 실행   3가지를 주는것이다.  rwx

5는  읽기와 씰행 권한을 주는 것이다.    r -x

4는 읽기 이다.   r


r은 뭐다?   읽기 이다.



421  rwx 이다.





umask

새 폴더, 새 파일의 퍼미션을 결정하는 값


umask  -S 옵션으로  rwx로 표시 해준다.


[root@ip-172-31-33-57 ~]# umask -S
u=rwx,g=rx,o=rx

umask 077 은    700 이다.   rwx --- ---  이다.

소유자 이외에는 아무권한도 주지 않는 것이다.

보안에 강한 권한.


Stick-bit  는  /tmp 다

공용폴더.

모든 이가 사용하는 폴더


t는 스티키  = 공용



Set G ID의 의미는?


프로그램이 실행되는 동안 프로세스는 파일의 그룹과 같은 권한으로 실행된다.

옵션 s로 표시된다.

chmod  s  /seo



Set - UID 는  파일이 실행하는 동인  실행시킨 사용자의 권한이 아민, 파일의 소유자로 인식한다.



감사합니다.

매거진의 이전글 15.리눅스 마스터 문제풀이2

작품 선택

키워드 선택 0 / 3 0

댓글여부

afliean
브런치는 최신 브라우저에 최적화 되어있습니다. IE chrome safari