Linux/Linux실습

Linux_p #11

broom7946 2023. 2. 13. 17:12

           관리자적 명령어들

 

1.    root 의 패스워드 변경하기

 

centos1 시작화면에서 i - e

 

->swap init=/bin/bash LANG=en_US.UTF-8

 

 

 

2.    부팅 정보를 가지고 있는 /etc/grub.conf 파일 잠궈두기

 

# ls -l /etc/grub2.cfg

 

# vi /boot/grub2/grub.cfg &

->백그라운드에 실행

 

# grub2-setpassword

->passwd 설정

 

# cat /boot/grub2/user.cfg

->해시 확인

 

# grub2-mkconfig -o /boot/grub2/grub.cfg

->해시된 것 적용

 

reboot

 

시작화면시 i - e

 

 

           Enter username:

           root

           rootoor

 

 

 

 

3.    chroot(change root)

  관리자는 서버 시스템에 FTP ,HTTP, NFS 등의 서버 서비스를 설정해두고, 클라이언트들이 FTP Telnet, SSH, HTTP 등으로 서버에 연결해서 파일을 업/다운로드하게 하는데 FTP 서버인 경우 FTP 서버의 오픈 디렉터리 /var/ftpd/pub 디렉터리, HTTP인 경우 /var/www/html 디렉터리로 들어와서 cd ../ ls ../ 해서 오픈된 pub 디렉터리의 상위 디렉터리로 이동하거나 살펴보게 하면 보안상 문제가 될 수 있다.

  이럴 때 chroot를 사용하는데 이 명령어는 어느 디렉터리를 가상의 최상위 / 디렉터리로 만들어서 cd ../ 했을 때 더 이상 상위 디렉터리로 이동하지 못하게 해서 보안을 증진시킨다.

  SSH 서비스가 있다는 것은 SSL로 이미 키를 사용해서 연결한다는 의미이다.

=>SSL(Secure Socket Layer) sftp, https, smtps, ... 등이 가능한 것이다.

 

# service sshd restart

 

# netstat -nltp |grep 22

 

 

--ubuntu

& sftp centos@192.168.100.129

 

 

pwd && ls

 

ls

 

 

cd etc

pwd

 

get passwd

!ls

 

!head -1 passwd              

 

--centos1

 

 

 

->두 그룹에 들어있음

 

->원본파일 백업

 

# vi /etc/ssh/sshd_config

 

 

->쓰기작업X 현재 root그룹

 

 

--ubuntu

 

pwd

->/ftp

 

cd ..

pwd

->/

 

ls

->ftp

 

cd /secure

->no

 

cd /ftp

mkdir tester1

ls /ftp

->/ftp/tester1

 

--centos1

# ls /secure/tester/ftp

->tester1

 


4.    chcon (change context)restorecon

 

# getsebool -a | grep ftp_home_dir

->on

 

->Enforcing

 

# firewall-cmd --permanent --add-port=80/tcp --zone=public

# firewall-cmd --reload

# yum -y install httpd httpd-manual

 

 

# cat -n /etc/httpd/conf/httpd.conf

->353줄에 IncludeOptional conf.d/*.conf

->메인 설정 파일은 여기 있는데

 

# getenforce

->Enforcing

 

# cp -arp /etc/httpd/conf/httpd.conf /etc/httpd/conf/httpd.conf.bak (파일 백업)

# nano /etc/httpd/conf/httpd.conf

->95#ServerName 주석 제거 -> 192.168.100.129:80

->353 Include~ 확인

 

# nano /etc/httpd/conf.d/web.conf

Alias /web /web/

<Directory /web>

Options Indexes

AllowOverride None

Order allow,deny

Allow from all

Require all granted

</Directory>

 

# apachectl configtest

 

# chmod 777 /web/index.html

# cat -n /etc/httpd/conf/httpd.conf

 

# service httpd restart

# echo "<h1>This is main Web page</h1>" > /var/www/html/index.html

 

# mkdir /web

# echo "<h2>This is Sub Web page</h2>" > /web/index.html

# chmod 777 /web/index.html

 

--bt

firefox http://192.168.100.143

->Forbidden

 

--centos1

# ls -dZ /web

# ls -dZ /var/www/html

 

# chcon -Rv --type=httpd_sys_content_t /web

 

#chocon -u centos_u /web

 

# chcon --reference=/var/www/html/index.html /web/index.html

# ls -dZ /web/index.html

 

# restorecon -R /web/

# ls -dZ /web/