ubuntu 기본 설정
sudo apt update && sudo apt -y upgrade
root@ubuntu-2gb-sin-2:~# sudo apt update && sudo apt -y upgrade
- SWAP메모리 배정
VPS는 메모리가 곧 매달 나가는 돈이다. 그래서 SSD용량을 조금 떼서(?) 메모리 인양 행사하는 놈을 SWAP메모리 라고 한다. - 기존 메모리의 2배를 통상적으로 배포한다.
free -h 확인후
root@ubuntu-2gb-sin-2:~# free -h
total used free shared buff/cache available
Mem: 1.9Gi 346Mi 872Mi 4.8Mi 871Mi 1.5Gi
Swap: 0B 0B 0B
root@ubuntu-2gb-sin-2:~#
root@ubuntu-2gb-sin-2:~#
root@ubuntu-2gb-sin-2:~#
root@ubuntu-2gb-sin-2:~# sudo fallocate -l 4G /swapfile
root@ubuntu-2gb-sin-2:~# chmod 600 /swapfile
root@ubuntu-2gb-sin-2:~# mkswap /swapfile
Setting up swapspace version 1, size = 4 GiB (4294963200 bytes)
no label, UUID=5f2e186c-c23d-4a44-850e-f0672f0c2e2b
root@ubuntu-2gb-sin-2:~# swapon /swapfile
root@ubuntu-2gb-sin-2:~# swapon --show
NAME TYPE SIZE USED PRIO
/swapfile file 4G 0B -2
root@ubuntu-2gb-sin-2:~# free -h
total used free shared buff/cache available
Mem: 1.9Gi 348Mi 868Mi 4.8Mi 872Mi 1.5Gi
Swap: 4.0Gi 0B 4.0Gi
root@ubuntu-2gb-sin-2:~#
아직 끝나지 않았다. fstab에 등록해 주지 않으면 재부팅시에는 날아간다. 그러므로
root@ubuntu-2gb-sin-2:~# vi /etc/fstab
/swapfile swap swap defaults 0 0
를 입력한 뒤 , 저장
- 방화벽 설정
last -10을 해보면
root@ubuntu-2gb-sin-2:~# lastb -10
solana ssh:notty 45.148.10.240 Thu Jul 10 19:39 - 19:39 (00:00)
solana ssh:notty 45.148.10.240 Thu Jul 10 19:39 - 19:39 (00:00)
ssh:notty 65.49.1.54 Thu Jul 10 19:34 - 19:34 (00:00)
sol ssh:notty 45.148.10.240 Thu Jul 10 19:33 - 19:33 (00:00)
sol ssh:notty 45.148.10.240 Thu Jul 10 19:33 - 19:33 (00:00)
vps ssh:notty 196.251.88.67 Thu Jul 10 17:51 - 17:51 (00:00)
vps ssh:notty 196.251.88.67 Thu Jul 10 17:51 - 17:51 (00:00)
alpine ssh:notty 196.251.88.67 Thu Jul 10 17:51 - 17:51 (00:00)
alpine ssh:notty 196.251.88.67 Thu Jul 10 17:51 - 17:51 (00:00)
sysadmin ssh:notty 196.251.88.67 Thu Jul 10 17:51 - 17:51 (00:00)
오늘 낮에 만들었는데도 득달같이 달려드는 놈들이 많다. brute force공격으로 봇으로 공격하는 거다. 나야 인증서로 로그인 해놓았으니..아!!! 비밀번호로 로그인 되는것도 잠궈야 한다.! 그래서 방화벽등 보안설정을 해놓는 것이다.
방화벽 설정
서버 방화벽 종류에는 firewalld, iptabls, ufw 가 있다. host.allow도 있는데 잘 안쓴다. iptables는 centos시절에 주로 썻던 놈이라
firewalld 와 ufw를 주로 쓰는데 ufw는 우분투에서 주로 쓰는 놈이라 범용으로는 firewalld를 주로 많이 사용한다. 하지만! ufw가 좀 편해서 한번 써보자
반드시!!! ssh포트가 막히지 않게 ssh포트부터 활성화 해줘야 한다. 막히면 vps 자체콘솔로 접속하거나 물리서버에 콘솔 꽂아도 되긴하지만...음...
그런다음 ufw 활성화root@ubuntu-2gb-sin-2:~# sudo ufw allow ssh
Rules updated
Rules updated (v6)
root@ubuntu-2gb-sin-2:~# ufw enable
Command may disrupt existing ssh connections. Proceed with operation (y|n)? y
Firewall is active and enabled on system startup
root@ubuntu-2gb-sin-2:~#
root@ubuntu-2gb-sin-2:~#
root@ubuntu-2gb-sin-2:~#
root@ubuntu-2gb-sin-2:~# ufw status verbose
Status: active
Logging: on (low)
Default: deny (incoming), allow (outgoing), disabled (routed)
New profiles: skip
To Action From
22/tcp ALLOW IN Anywhere
22/tcp (v6) ALLOW IN Anywhere (v6)
root@ubuntu-2gb-sin-2:~#
ssh가 끊길수도 있다고 경고한다. 쫄지 마시오
나머지 http, https 도 추가(웹서버 만들려면)
나는 집, 회사, vpn의 ip를 CIDR 24로 추가하고 난뒤 22번 포트를 막아버린다.
그러면 외부에서 접속할때도 vpn으로 접속하면 그만이다.
vpn은 zerotier를 깔았다.
ssh설정- 비밀키를 통해서 로그인
안했을때: ssh root@ip => 비밀번호 접속
했을때: ssh root@ip=> 바로 접속됨
id_rsa 와 authorized_keys 만 매칭 되면 끝
/etc/hosts :세팅시 ip를 입력하지 않아도 서버간 rsync, ssh 접속이 가능하다.
안했을때: ssh root@ip
했을때: ssh root@노드명
ex) jaegon 10.123.123.123
~/.ssh/config : 위에는 ip를 안쳐도 되는 정도지만 이건 더 심플하게 접속 가능
안했을때 : ssh root@노드 or ip
했을때: ssh jaegon => 바로 접속됨(비밀키 설정을 해 놔야 함)
Host jaegon
HostName 10.123.12.123
User root
jaegon은 node 이름이고
hostname에는 ip 주소
user는 접속하고자 하는 사용자명