0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

[超簡単!]UbuntuでVNC接続する方法(自分が手順を忘れないように作成しました。)

Posted at

Ubuntu Server GUI & VNC セットアップマニュアル

システム要件

  • Ubuntu Server 22.04 LTS または 24.04 LTS
  • 最低2GB RAM(4GB以上推奨)
  • 20GB以上のストレージ空き容量

❶ 初期設定

1. システム更新

sudo apt update && sudo apt upgrade -y
sudo apt install -y net-tools

2. 日本語環境設定(オプション)

sudo apt install -y language-pack-ja
sudo update-locale LANG=ja_JP.UTF-8
sudo timedatectl set-timezone Asia/Tokyo

❷ GUI環境のインストール

3. XFCEデスクトップのインストール

sudo apt install -y xfce4 xfce4-goodies xorg dbus-x11

4. 日本語入力設定(オプション)

sudo apt install -y fcitx-mozc fcitx-config-gtk

❸ VNCサーバーのインストールと設定

5. TigerVNCのインストール

sudo apt install -y tigervnc-standalone-server tigervnc-xorg-extension

6. VNCパスワードの設定

vncpasswd
# 8文字以上のパスワードを設定

7. xstartupファイルの作成

mkdir -p ~/.vnc
echo '#!/bin/bash
unset SESSION_MANAGER
unset DBUS_SESSION_BUS_ADDRESS
export XKL_XMODMAP_DISABLE=1
xsetroot -solid grey
xrdb $HOME/.Xresources
exec startxfce4' > ~/.vnc/xstartup

chmod +x ~/.vnc/xstartup
touch ~/.Xresources

❹ ファイアウォール設定

8. VNCポートの開放

sudo ufw allow 5901/tcp
sudo ufw allow 5902/tcp
sudo ufw enable

❺ VNCサービスの起動

9. VNCサーバーの起動

# ディスプレイ:1で起動(ポート5901)
vncserver :1 -geometry 1920x1080 -depth 24 -localhost no

# または解像度を指定
vncserver :1 -geometry 1280x720 -depth 24 -localhost no

10. 自動起動設定(オプション)

# サービスファイル作成
echo '[Unit]
Description=TigerVNC Server
After=syslog.target network.target

[Service]
Type=simple
User=anchovy-nas
PAMName=login
PIDFile=/home/anchovy-nas/.vnc/%H:%i.pid
ExecStartPre=/bin/sh -c '/usr/bin/vncserver -kill :%i > /dev/null 2>&1 || :'
ExecStart=/usr/bin/vncserver :%i -geometry 1920x1080 -depth 24 -localhost no
ExecStop=/usr/bin/vncserver -kill :%i

[Install]
WantedBy=multi-user.target' | sudo tee /etc/systemd/system/vncserver@.service

# サービス有効化
sudo systemctl daemon-reload
sudo systemctl enable vncserver@1.service
sudo systemctl start vncserver@1.service

❻ 接続情報

11. 接続詳細

  • VNCアドレス: あなたのサーバーIP:5901
  • 表示番号: :1
  • 認証方式: VNCパスワード
  • 推奨VNCクライアント: TigerVNC Viewer, RealVNC Viewer
  • 接続例: 10.100.100.1:5901

12. IPアドレスの確認

hostname -I
ip addr show

❼ トラブルシューティング

13. よくある問題と解決策

接続できない場合

# ファイアウォール確認
sudo ufw status

# VNCプロセス確認
ps aux | grep vnc

# ポートリスニング確認
netstat -tlnp | grep 590

灰色画面が表示される場合

# xstartupファイルの再設定
cp ~/.vnc/xstartup ~/.vnc/xstartup.bak
echo '#!/bin/bash
xterm' > ~/.vnc/xstartup
chmod +x ~/.vnc/xstartup

パーミッションエラー

sudo chmod +x ~/.vnc/xstartup
sudo chown -R $USER:$USER ~/.vnc

❽ 管理コマンド集

14. 常用コマンド

# VNCサーバー起動
vncserver :1 -localhost no

# 特定のディスプレイを停止
vncserver -kill :1

# 全てのVNCセッションを停止
pkill -9 Xtigervnc

# 実行中のセッション確認
netstat -tlnp | grep 590

# ログ確認
tail -f ~/.vnc/anchovy-nas:1.log

15. サービス管理

# サービス状態確認
sudo systemctl status vncserver@1

# サービス再起動
sudo systemctl restart vncserver@1

# サービス停止
sudo systemctl stop vncserver@1

❾ セキュリティ設定

16. SSHトンネル経由接続(推奨)

# クライアント側で実行
ssh -L 5901:localhost:5901 username@server-ip

# その後localhost:1に接続

17. パスワード強化

# 定期的なパスワード変更
vncpasswd

❿ バックアップと復元

18. 設定のバックアップ

# VNC設定のバックアップ
tar -czf vnc-backup.tar.gz ~/.vnc/

# 復元時
tar -xzf vnc-backup.tar.gz -C ~/

⓫ アンインストール手順

19. 完全アンインストール

# VNCサーバーの停止
vncserver -kill :1
sudo systemctl stop vncserver@1
sudo systemctl disable vncserver@1

# パッケージ削除
sudo apt remove --purge tigervnc-standalone-server -y
sudo apt autoremove -y

# 設定ファイル削除
rm -rf ~/.vnc

⓬ 注意事項

  1. セキュリティ: インターネットに公開する場合はSSHトンネル必須
  2. パフォーマンス: 低スペックマシンでは解像度を下げる
  3. バックアップ: 設定変更前にはバックアップを取得
  4. ログ: 問題発生時は ~/.vnc/*.log を確認

このマニュアルを参考に、安全で快適なリモートデスクトップ環境を構築してください。

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?