# Linux ์๋ฒ ๊ด๋ฆฌ ์๋ฒฝ ๊ฐ์ด๋
## ํ์ต ๋ชฉํ
Linux ์๋ฒ๋ฅผ ์ง์ ๊ด๋ฆฌํ๊ณ ์ด์ํ ์ ์๋ ์ญ๋์ ํค์๋๋ค.
## 1. ๊ธฐ๋ณธ ๋ช
๋ น์ด
ls -la # ์์ธ ๋ชฉ๋ก
cd /var/www # ๋๋ ํ ๋ฆฌ ์ด๋
pwd # ํ์ฌ ๊ฒฝ๋ก
mkdir -p a/b/c # ์ค์ฒฉ ๋๋ ํ ๋ฆฌ ์์ฑ
rm -rf folder # ํด๋ ์ญ์
cp file1 file2 # ๋ณต์ฌ
mv file1 file2 # ์ด๋/์ด๋ฆ๋ณ๊ฒฝ
cat file # ํ์ผ ๋ด์ฉ ๋ณด๊ธฐ
less file # ํ์ด์ง ๋จ์๋ก ๋ณด๊ธฐ
head -n 20 file # ์ฒ์ 20์ค
tail -f log.txt # ์ค์๊ฐ ๋ก๊ทธ ๋ณด๊ธฐ
## 2. ํ์ผ ๊ถํ ๊ด๋ฆฌ
ls -la
# -rwxr-xr-x = ์์ ์(rwx) ๊ทธ๋ฃน(r-x) ๊ธฐํ(r-x)
chmod 755 script.sh # rwxr-xr-x
chmod +x script.sh # ์คํ ๊ถํ ์ถ๊ฐ
chmod -R 644 folder # ์ฌ๊ท์ ์ ์ฉ
chown user:group file
chown -R www-data:www-data /var/www
## 3. ํจํค์ง ๊ด๋ฆฌ
apt update # ํจํค์ง ๋ชฉ๋ก ๊ฐฑ์
apt upgrade # ์ ์ฒด ์
๊ทธ๋ ์ด๋
apt install nginx # ์ค์น
apt remove nginx # ์ ๊ฑฐ
apt autoremove # ๋ถํ์ํ ํจํค์ง ์ ๊ฑฐ
## 4. ํ๋ก์ธ์ค ๊ด๋ฆฌ
ps aux # ์ ์ฒด ํ๋ก์ธ์ค
ps aux | grep nginx # ํํฐ๋ง
top # ์ค์๊ฐ ๋ชจ๋ํฐ๋ง
htop # ํฅ์๋ ๋ชจ๋ํฐ๋ง
kill 1234 # PID๋ก ์ข
๋ฃ
kill -9 1234 # ๊ฐ์ ์ข
๋ฃ
killall nginx # ์ด๋ฆ์ผ๋ก ์ข
๋ฃ
## 5. ์๋น์ค(Systemd) ๊ด๋ฆฌ
systemctl start nginx # ์์
systemctl stop nginx # ์ค์ง
systemctl restart nginx # ์ฌ์์
systemctl reload nginx # ์ค์ ๋ฆฌ๋ก๋
systemctl status nginx # ์ํ ํ์ธ
systemctl enable nginx # ๋ถํ
์ ์๋ ์์
systemctl disable nginx
journalctl -u nginx -f # ์ค์๊ฐ ๋ก๊ทธ
## 6. ๋คํธ์ํฌ ๊ด๋ฆฌ
ip addr
ifconfig
netstat -tulpn # ์ด๋ฆฐ ํฌํธ
ss -tulpn # ๋ ๋น ๋ฅธ ๋์
lsof -i :80 # 80ํฌํธ ์ฌ์ฉ ํ๋ก์ธ์ค
ping google.com
curl -I https://example.com
## 7. ๋ฐฉํ๋ฒฝ (UFW)
ufw status
ufw enable
ufw allow 80/tcp
ufw allow 443/tcp
ufw allow from 192.168.1.0/24
ufw deny 3306
ufw delete allow 80/tcp
## 8. SSH ์ ์ ๋ฐ ๋ณด์
ssh user@host
ssh -p 2222 user@host
ssh -i key.pem user@host
ssh-keygen -t ed25519
ssh-copy-id user@host
# /etc/ssh/sshd_config
Port 2222
PermitRootLogin no
PasswordAuthentication no
## 9. ๋์คํฌ ๊ด๋ฆฌ
df -h # ๋ง์ดํธ๋ ๋์คํฌ
du -sh /var # ํด๋ ํฌ๊ธฐ
du -sh * | sort -h # ํฌ๊ธฐ์ ์ ๋ ฌ
lsblk # ๋ธ๋ก ์ฅ์น ๋ชฉ๋ก
fdisk -l # ํํฐ์
์ ๋ณด
mount /dev/sdb1 /mnt/data
umount /mnt/data
## 10. ๋ก๊ทธ ๋ถ์
/var/log/syslog # ์์คํ
๋ก๊ทธ
/var/log/auth.log # ์ธ์ฆ ๋ก๊ทธ
/var/log/nginx/ # Nginx ๋ก๊ทธ
tail -f /var/log/syslog
grep "error" /var/log/nginx/error.log
## 11. Cron ์ค์ผ์ค๋ง
crontab -e
# ํ์: ๋ถ ์ ์ผ ์ ์์ผ ๋ช
๋ น
0 2 * * * /backup.sh # ๋งค์ผ 2์
*/5 * * * * /check.sh # 5๋ถ๋ง๋ค
0 0 * * 0 /weekly.sh # ๋งค์ฃผ ์ผ์์ผ
crontab -l # ํ์ธ
## ์ถ์ฒ ํ์ต ์์
1. ๊ธฐ๋ณธ ๋ช
๋ น์ด ์๋ฌ
2. ํ์ผ ๊ถํ ์ดํด
3. ์๋น์ค ๊ด๋ฆฌ ์ตํ๊ธฐ
4. SSH ๋ณด์ ์ค์
5. ์๋ํ ์คํฌ๋ฆฝํธ ์์ฑ