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?

KaliでVNCを設定する方法

Last updated at Posted at 2025-04-14

はじめに

こんにちは!高校生でプログラミング勉強中のCureSabaです。

今回はkaliでvncを設定したのですが少し手間取ったので記事に残します。
参考になれば光栄です!

手順

tightvncserverの修正

kaliにはデフォルトでtightvncserverがインストールされているのですが、こいつはtightvncserver: couldn't find "vncpasswd" on your PATH.と出て何故か違う実行ファイルを読み込もうとするので直します

sudo sed -i 's/vncpasswd/tightvncpasswd/g' /usr/bin/tightvncserver

これでvncpasswdtightvncpasswdに置き換えます

VNCの修正

今VNCで開くと灰色の画面にバツ印が出るだけなので直します

一応バックアップ

cp ~/.vnc/xstartup ~/.vnc/xstartup.bak

編集

sudo nano ~/.vnc/xstartup

置換

~/.vnc/xstartupを下の通りに置換する

~/.vnc/xstartup
#!/bin/sh

unset SESSION_MANAGER
unset DBUS_SESSION_BUS_ADDRESS
startxfce4 &

[ -x /etc/vnc/xstartup ] && exec /etc/vnc/xstartup
[ -r $HOME/.Xresources ] && xrdb $HOME/.Xresources
xsetroot -solid grey
vncconfig -iconic &

ufw設定

ufwに穴を開けておく(今回はディスプレイ1を使用する場合)

sudo ufw allow 5901

起動

下に従って起動

tightvncserverの使い方

起動

ディスプレイ番号をセットしなければ勝手に1になる
ポートは5900+ディスプレイ番号

tightvncserver :ディスプレイ番号

停止

tightvncserver -kill :ディスプレイ番号

画面解像度変更

設定からは変更できないので実行前に変更する必要あり
px単位で指定

tightvncserver :ディスプレイ番号 -geometry 幅x高さ

任意のポートにする

tightvncserver :ディスプレイ番号 -httpport ポート番号

おまけ

systemctl登録

VPS起動時に起動するようにsystemctl登録

sudo nano /etc/systemd/system/tightvncserver.service
/etc/systemd/system/tightvncserver.service
[Unit]
Description=Tight VNC
After=syslog.target network.target

[Service]
Type=forking
User=ユーザー名
ExecStartPre=-/usr/bin/tightvncserver -kill :1 > /dev/null 2>&1
ExecStart=/usr/bin/tightvncserver :1 -geometry 1920x1080
ExecStop=/usr/bin/tightvncserver -kill :1

[Install]
WantedBy=multi-user.target
sudo systemctl daemon-reload
sudo systemctl enable tightvncserver.service
sudo systemctl start tightvncserver.service

終わりに

もし、この記事が役に立ったと思ったら、ぜひコメントやシェアをお願いします。また、質問や改善点などがあれば気軽にコメントしてください!

それでは、良いプログラミングライフを!

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?