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初期設定とリモートデスクトップの設定

Last updated at Posted at 2025-05-22

Ubuntu 24.04.2 LTSをクリーンインストールしたので,その際に行った初期設定もろもろを覚書。

パッケージの更新

$ sudo apt-get update
$ sudo apt-get upgrade

パッケージの自動アップデートの設定

unattended-upgradesのインストール

$ sudo apt-get install unattended-upgrades

有効化

$ sudo dpkg-reconfigure -plow unattended-upgrades

<Yes>を選択
updatesのコメントアウトを外す

/etc/apt/apt.conf.d/50unattended-upgrades
    // Automatically upgrade packages from these (origin:archive) pairs
	Unattended-Upgrade::Allowed-Origins {
	        "${distro_id}:${distro_codename}-security";
-	//      "${distro_id}:${distro_codename}-updates";
+	        "${distro_id}:${distro_codename}-updates";
	//      "${distro_id}:${distro_codename}-proposed";
	//      "${distro_id}:${distro_codename}-backports";
	};

日本語入力

mozcをインストール

$ sudo apt install -y ibus-mozc
$ sudo apt install -y mozc-utils-gui

sudo rebootした後Settingsを開き,Keyboard > Input SourcesJapanese (Mozc)およびJapanese (OADG 109A)を追加。

キーボードの設定

$ sudo dpkg-reconfigure keyboard-configuration

Generic 104-key PC with L-shaped Enter key > Japanese > Japanese - Japanese (OADG 109A) > The default for the keyboard layout > No compose key > Yes

Caps Lockを日本語/英語入力切り替えに割り当てる

キーの割り当ての変更

Caps_LockZenkaku_Hankakuを入れ替え
xmodmapでキー割り当てを確認

~/.Xmodmap
remove lock = Eisu_toggle
add lock = Zankaku_Hankaku
~$ xmodmap .Xmodmap

~/.bashrcの最後尾に以下を追記

~/.bashrc
xmodmap ~/.Xmodmap

日本語/英語入力切替(IME切り替え)のショートカットの設定

Settings > Keyboard > Keyboard Shortcuts > View and Customize Shortcuts > Typing > Switch to next input sourceEisu toggle

良く使うソフトのインストール

gedit

$ sudo apt install gedit

VSCode

$ sudo apt install curl
$ curl -L https://go.microsoft.com/fwlink/?LinkID=760868 -o vscode.deb
$ sudo apt install ./vscode.deb

Google Chrome

$ curl -LO https://dl.google.com/linux/direct/google-chrome-stable_current_amd64.deb
$ sudo apt install ./google-chrome-stable_current_amd64.deb

ClamAV(ウイルス対策ソフト)

$ sudo apt install clamav clamav-daemon
$ sudo systemctl start clamav-daemon 
$ sudo systemctl status clamav-daemon 

確認してもactiveになっていなかったので再起動したら直った。

$ sudo systemctl restart clamav-freshclam
$ sudo systemctl restart clamav-daemon

スキャン

$ sudo clamdscan --fdpass /path/to/scan/target

リモートデスクトップの設定(ローカル)

Desktop Sharingの有効化

Settingsを開き,System > Remote Desktop > Desktop SharingRemote Controlのトグルをオン。microsoftのRDPを使用している。xrdpなどの面倒な設定は不要。

ローカルのWindowsクライアントから接続

Windows + Rでプログラム名mstscを指定してリモートデスクトップ接続を開き,Ubuntuのホスト名に.localを付与したものを入力。
Login Detailsで設定されたユーザー名とパスワードでログイン。

リモートデスクトップの設定(LANの外から)

Desktop Sharingを使用して接続してもいいのだが,ポート開放が必要だしセキュリティリスクも上昇する。VPN対応ルーターを導入してもいいがコストがかかる。
そこでchromeリモートデスクトップを使用する。

SSH経由でセットアップする

  1. ホスト側のUbuntuからChromeで上のリンクにアクセス
  2. リンク先のソフトをインストール
  3. 指示に従ってコマンドを実行
  4. Ubuntuをログアウト
    ログアウトしないと接続できないので注意
  5. クライアント側のChromeで上のリンクにアクセス
    リモートのデバイスに表示されたコンピュータ名をクリックで接続できる
    XSession, Ubuntu (Wayland), Ubuntu on Xorgのどれかを選択
    下記の設定のためUbuntu on Xorgを選択

Ubuntuの自動スリープを無効にする

スリープ等してしまうと接続できなくなってしまうので,自動スリープを無効にする

sudo systemctl mask sleep.target suspend.target hibernate.target hybrid-sleep.target

戻すときは次のようにする

sudo systemctl unmask sleep.target suspend.target hibernate.target hybrid-sleep.target

Ubuntu側でログインしている画面をリモートで操作できるようにする

同一アカウントでの同時ログインはできないので、Ubuntu側でログインしている画面を参照できるようにChromeリモートデスクトップの設定を変更する。

Chromeリモートデスクトップの停止

$ /opt/google/chrome-remote-desktop/chrome-remote-desktop --stop

設定ファイルの編集

$ sudo gedit /opt/google/chrome-remote-desktop/chrome-remote-desktop
  1. FIRST_X_DISPLAY_NUMBERの変更
    X Window Systemにおいてアプリケーションをどのディスプレイに表示させるかを設定するDISPLAY環境変数を確認
    $ echo $DISPLAY
    :1 // 出力結果 (ホスト):(ディスプレイ).(スクリーン)
    
    ここで表示されたディスプレイ番号を設定
    /opt/google/chrome-remote-desktop/chrome-remote-desktop
    - FIRST_X_DISPLAY_NUMBER = 20
    + FIRST_X_DISPLAY_NUMBER = 1 //ここにディスプレイ番号を設定
    
  2. launch_session()の修正
    使用するディスプレイを明示
    /opt/google/chrome-remote-desktop/chrome-remote-desktop
    def launch_session(self, server_args, backoff_time):
        """Launches process required for session and records the backoff time
        for inhibitors so that process restarts are not attempted again until
        that time has passed."""
        logging.info("Setting up and launching session")
        self._setup_gnubby()
    -   self._launch_server(server_args)
    +   # self._launch_server(server_args)
    -   if not self._launch_pre_session():
    -   # If there was no pre-session script, launch the session immediately.
    -       self.launch_desktop_session()
    +   # if not self._launch_pre_session():
    +   # If there was no pre-session script, launch the session immediately.
    +   #   self.launch_desktop_session()
    +   display = self.get_unused_display_number()
    +   self.child_env["DISPLAY"] = ":%d" % display
        self.server_inhibitor.record_started(MINIMUM_PROCESS_LIFETIME,
                                      backoff_time)
        self.session_inhibitor.record_started(MINIMUM_PROCESS_LIFETIME,
                                     backoff_time)
    

chromeリモートデスクトップの起動

$ /opt/google/chrome-remote-desktop/chrome-remote-desktop --start

session already runningでログインできないとき

chromeリモートデスクトップを削除して再インストール

  1. セッションの停止
    Ctr+Alt+F2でCUI環境に変更し、エラーが発生しているユーザーでログイン。セッションの停止。
    $ sudo pkill -KILL -u <username>
    
  2. chromeリモートデスクトップのアンインストール
    $ sudo apt-get remove --purge chrome-remote-desktop
    
  3. 関連ファイルの削除
    $ sudo rm -rf ~/.config/chrome-remote-desktop
    
  4. 再起動
    $ sudo shutdown -r now
    
  5. 再インストールと再設定

WindowsからchromeリモートデスクトップでUbuntuに接続すると右シフトキーが反応しない問題

xevでイベント検出もされない。chromeリモートデスクトップの右側の設定でキーマッピングを変更しても解決しなかった。そこでPowerToysのKeyboard Managerを使ってShift(Right)をShift(Left)に再マップした。

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?