본문 바로가기

개발기술/빌드, 배포, 운영

원격제어

MobaXterm 

MobaXterm is an all-in-one remote access tool for Windows that supports:

  • SSH (Secure Shell)
  • X11 Forwarding
  • VNC (Virtual Network Computing) with built-in VNC viewer!
  • RDP (Remote Desktop Protocol)
  • FTP/SFTP (File Transfer Protocols)

 

VNC (Virtual Network Computing)

  • VNC (Virtual Network Computing) is a remote desktop sharing system that allows users to control a computer remotely by transmitting the screen display and keyboard/mouse input over a network.
    • X11 forwarding is for individual windows sharing whereas VNC creates a full desktop session that can be accessed remotely.
  • Docker's Case
    • Since docker do not have a GUI by default, Before installing VNC, we need to install Virtual X Display setting
      • GUI applications  send rendering commands (like "draw a button here") to an X server, which handles the actual drawing. so we need middle man to receive GUI Command Before transfering GUI signal to outside
      • Some VNC such as TigerVNC create virtual display and VNC Session as well
  • How does VNC Work?  
    • A VNC server the machine that you want to control run on local host
    • Create Port Forwarding between local machine and server to control
      • The ISP's gateway (public internet) is outside your control, but you can use VPN, or SSH tunneling to bypass this limitation.
    • Uses the RFB (Remote FrameBuffer) protocol to transmit screen updates.
      • In a real Linux desktop, DISPLAY=:0 represents the actual screen.
      • VNC Server (x11vnc) : Even though Xvfb lets GUI apps run, it doesn’t let you see them from outside Docker. A VNC server is needed to capture the virtual X display and send it over the network

 

Display Protocol

  •   A display protocol is a system that defines how graphical applications (clients) communicate with the display server to render graphics and receive user input (keyboard, mouse, etc.)
  • GUI applications need a standardized way to send graphics to the screen. The display server (like the X Server or Wayland) needs a protocol to receive drawing requests from apps.
  • Common Display Protocols
    • X11 (X Window System)
      • Oldest and most widely used display protocol (1984). X11 is an OS-level application that enables GUI rendering.
      • Apps (X Clients) send drawing requests to the X Server, which renders them.
      • Supports network-based GUI apps (run apps remotely over SSH).
    • Wayland (The Modern Replacement for X11)
      • Designed as a replacement for X11 (simpler & more secure).

 

 

X display's Display Variable

  • DISPLAY variable determines which screen session an application should render to.
    • hostname → (Optional) The machine running the X server.
    • display → The X display number, indicating an X session.
    • screen → The screen number (rarely used, default is 0).
DISPLAY=[hostname]:[display].[screen]
  • Common DISPLAY Values
    • DISPLAY=:0 → The Physical Display
      • This is the default X display used by the main GUI session.
    • DISPLAY=:1, :2, etc. → Virtual Displays (Used by VNC & Xvfb)
      • If you start a VNC session, it creates a new virtual X display, like :1, :2, etc.
      • This allows multiple GUI sessions to run independently of the main display (:0).
    • When we access to VNC session, we should check if DISPLAY variable matched with VNC server so the gui application that we will launch show on the right virtual screen

 

VNC Session Setting 

  • Run VNC Server on Remote Computer
  • Port forward to Local computer for VNC Server
  • Access to VNC Server using client
  • Check $Display Varible if its matching VNC Server's number(Virtual Display Number)
  • Run GUI Application you want

 

 

 

 

 

 

VPN설정

VPN은 "가상의 사설 네트워크"를 만들어서 보안이 강화된 네트워크 환경을 제공하는 기술이야.
 외부에서도 내부 네트워크에 안전하게 접속할 수 있도록 해 줌.
 기업이나 조직에서는 개발자가 VPN을 통해 내부 서버에 접근하도록 설정하는 경우가 많음.

📌 VPN의 주요 개념

  • 🔹 가상 사설 네트워크(VPN): 인터넷을 통해 안전한 연결을 생성하여 내부 네트워크에 접속 가능
  • 🔹 IP 주소 변경: VPN을 사용하면 외부에서 접근할 때 VPN 서버의 IP로 보이게 됨
  • 🔹 암호화된 통신: 모든 트래픽이 암호화되므로 해킹이나 패킷 가로채기 공격을 방지
  • 🔹 내부 리소스 접근 가능: 회사 내부의 DB, API, 파일 서버 등에 안전하게 접속

 

 

리눅스 SSH(Secure Shell)

 

파일 전송 

  •  
  • 원격 서버와의 파일 업로드 및 다운로드 작업을 수행할 수 있습니다

 

SSH (Secure Shell) 개념과 설정 방법

  • SSH (Secure Shell)**는 원격 서버에 인터넷을 통해 안전하게 접속할 수 있도록 하는 네트워크 프로토콜 및 프로그램
  • SSH의 주요 기능
    • 원격 서버 로그인 (ssh user@server-ip)
    • 원격 명령 실행 (ssh user@server-ip "command")
    • 파일 전송 (scp, rsync)
    • 포트 포워딩 (터널링, X11 Forwarding)

SSH 기본 설치 및 설정 방법

  • SSH 설치 확인 (Ubuntu & CentOS) : 리눅스 배포판은 기본적으로 SSH가 설치되어 있지만, 없을 경우 직접 설
sudo apt update
sudo apt install -y openssh-server
  • 서버 설정 파일 (/etc/ssh/sshd_config) : SSH 보안 및 접속 관련 설정을 변경하려면 설정 파일을 수정해야 합니다.
sudo nano /etc/ssh/sshd_config
설정  항목 설명 기본값
Port 22 SSH 기본 포트 (변경 가능) 22
PermitRootLogin no root 계정 SSH 접속 차단 no
PasswordAuthentication yes 비밀번호 로그인 허용 여부 yes
PubkeyAuthentication yes 공개키 인증 활성화 여부 yes

 

  • 서버에서 계정 생성하기
    • SSH는 기본적으로 리눅스의 사용자 계정을 기반으로 동작하므로, 따로 SSH만을 위한 계정을 만들 필요가 없습니다.
    • SSH 접속을 위해 새로운 계정을 만들려면 root 또는 sudo 권한이 필요합니다.
sudo adduser myuser
sudo passwd myuser

 

원격 서버 로그인

  • SSH 접속 방법 : 비밀번호 로그인으로 SSH 접속
    • 기본적으로 서버 계정 비밀번호를 입력하여 SSH 접속 가능합니다.
ssh user@server-ip

 

 

 

명령어 정리

  • ssh user@hostname : 원격 서버에 연결. 기본적으로 사용자 이름과 비밀번호를 요청함.
  • ssh -i /path/to/private_key user@hostname : 개인 키를 사용해 비밀번호 없이 연결.
  • ssh -p 2222 user@hostname : 포트 지정. 기본 SSH 포트(22)가 아닌 사용자 지정 포트로 연결.
  • ssh user@hostname "ls -l /var/www" : SSH 연결 후 원격 서버에서 특정 명령어 실행.
  • ssh -A user@hostname : SSH Agent Forwarding을 활성화하여, 현재 SSH 세션에서 개인 키 인증을 다른 서버로 전달.
  • ssh -L 8080:localhost:80 user@hostname : 내 로컬 머신의 8080 포트로 접속하면, 원격 서버의 80 포트로 전달.
  • ssh -R 8080:localhost:80 user@hostname : 원격 서버의 8080 포트로 접속하면, 내 로컬 머신의 80 포트로 전달.
  • ssh -f -N user@hostname  : SSH 연결은 유지하되, 명령어 실행 없이 백그라운드에서 실행.

 

 

 

포트 포워딩 (터널링, X11 Forwarding)

  • Port forwarding is used to tunnel traffic securely between two machines. 
    • Accessing services running on a private network (NAT traversal)
    •  Bypass network restrictions by tunneling all traffic through an SSH server (like a VPN).  Hosting servers behind a firewall (e.g., web, gaming, VNC, RDP)
      • ISP's Internet gatway cannot be controlled by individual so we need bypassing way
  • Local Port Forwarding (-L)
    • Syntax  : ssh -L [local-port]:[destination-ip]:[destination-port] -N -f -l user remote-server.com
    • As Client of Service, turnel a local port that forwards request traffic to the remote machine to access a remote service from your local machine
      • A database is running on remote-server.com:5432 (PostgreSQL).
      • You want to access this database locally as if it were running on localhost:5432.
      • After running the command, Even though the database is on remote-server.com, it appears as if it's running locally on your machine (127.0.0.1:5432).
  • How Remote Port Forwarding (-R) Works
    • Syntax : ssh -R [remote-port]:[local-ip]:[local-port] -N -f -l user remote-server.com
    • As a client, you create a secure SSH tunnel that opens a port on the remote machine, forwarding request traffic from remote port to your local machine, allowing the remote machine to access your locally hosted service.
      • Your local machine has a web server running on 127.0.0.1:8000
      • The remote machine (remote-server.com) is instructed to forward incoming traffic on 8080 to your local web server (127.0.0.1:8000).
      • After running this command, someone on remote-server.com can access your local web server by visiting: http://localhost:8080
  • Command Execution Option
    • -N (No Remote Command Execution) : set up port forwarding (tunneling) without running an interactive shell or executing commands on the remote server.
    • -f (Fork to Background) : tells SSH to run in the background after authentication.
    • - l (Specify Remote Username) : This option specifies the remote username for authentication. Without -l, SSH will use the current logged-in user's name.

 

 

 

 

 

 

 

AWS 보안 그룹 설정

  • AWS 사용 : AWS EC2에 접속하여 서버를 관리하는 가장 기본적인 사용법입니다.
  • EC2 인스턴스를 생성할 때 보안 그룹(Security Group)은 기본적으로 모든 포트가 닫혀 있습니다. 즉, 인바운드 트래픽은 허용되지 않으며, 아웃바운드 트래픽은 기본적으로 모두 허용됩니다.
  • SSH 접속을 위해 AWS 보안 그룹에서 TCP 포트 22를 열어야 합니다. 일반적으로 접속 가능한 IP를 제한하여 보안을 강화합니다
  • AWS 사용 :보안 그룹 설정: 포트 22 열기 및 접속 IP 제한. 기본설정은 포트 22번 열려있으며 ip제한 없음.

 

 

 

파일 전송 (scp, rsync)

 

SSH를 기반으로 파일을 안전하게 전송하는 방식

 

  • SSH는 SCP(Secure Copy Protocol) 및 **SFTP(Secure File Transfer Protocol)**를 통해 안전한 파일 전송을 지원합니다.
  • scp /path/to/local_file user@hostname:/path/to/remote_directory :  로컬에서 원격 서버로 파일 전송
  • scp user@hostname:/path/to/remote_file /path/to/local_directory : 원격서버에서 로컬로 파일 다운로 
  • scp -r /path/to/local_directory user@hostname:/path/to/remote_directory : 디렉토리를 재귀적으로 전송

 

scp [옵션] <로컬_파일_경로> <사용자>@<원격_주소>:<목적지_경로>

 

'개발기술 > 빌드, 배포, 운영' 카테고리의 다른 글

쉘 커맨드 , 쉘 스크립트  (0) 2025.03.25
Jenkins CI/CD 자동화  (0) 2025.01.26
Gradle 빌드 사용법  (0) 2025.01.02
빌드와 Gradle 개념  (0) 2024.11.12
빌드 파일 서버 배포  (0) 2024.11.12