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?

Virtual Box でクローン

Last updated at Posted at 2024-07-02

目的

  • クローン後のホスト名や固定IP設定などをまとめる

前提

  • クローン元のホストの名前をmomongaとする
  • クローン先のホストの名前をmarmosetとする
  • momongaのIPアドレスを 192.168.56.120、marmosetのIPアドレスを 192.168.56.130 とする

クローンからリモート接続まで

クローンする

  1. Virtual Box起動
  2. momonga を右クリックして「クローン」をクリック
  3. 名前に marmoset と入力して「次へ」をクリック
  4. 「すべてをクローン」が選択されていることを確認して「完了」をクリック
    暫く待つとmarmosetが作成されるので、右クリック→起動→通常起動 でサーバーを起動

ホスト名変更

  1. VirtualBox のコンソールでrootでログイン(パスワードはmomongaと同じ)
  2. ホスト名変更
[root@momonga ~]# hostname
momonga
[root@momonga ~]# hostnamectl set-hostname marmoset
[root@momonga ~]# hostname
marmoset

※ 後でリブートして反映させます

固定IP割り振り

nmtui コマンドで設定します。
hostonlyアダプタ(ホスト・ゲスト間の通信)とnatnetworkアダプタの設定をします。

[root@momonga ~]# nmtui

(以下UI画面で設定)
Edit a connection を選んで Enter

hostonlyアダプタの設定

enp0s8 を選んで Enter
IPv4 CONFIGURATION
Address 192.168.56.130/24
Gateway (空欄)
チェック項目は全てチェックなし
[X] Automatically connect
[X] Available to all users

natnetworkアダプタの設定

enp0s3 を選んで Enter
IPv4 CONFIGURATION
Address 10.0.2.130/24
Gateway 10.0.2.1
DNS servers 10.0.2.1
チェック項目は全てチェックなし
[X] Automatically connect
[X] Available to all users

Quit で Enter
再起動

[root@momonga ~]# reboot

NATネットワークのゲートウェイ確認

nameserver の値が DNS servers で指定した値と同じか確認する(違う場合は修正)

[root@momonga ~]# cat /etc/resolve.conf
# Generated by NetworkManager
nameserver 10.0.2.1

ユーザー削除と作成

リモートホストにrootでログインして、marmosetユーザーを作ります。

// wheelグループでmarmosetを追加
[root@marmoset ~]# useradd marmoset -g wheel

// パスワード設定
[root@marmoset ~]# passwd marmoset
Changing password for user marmoset.
New password:
Retype new password:
passwd: all authentication tokens updated successfully.

// 確認
[root@marmoset ~]# cat /etc/passwd | grep marmoset
marmoset:x:1002:10::/home/marmoset:/bin/bash

同時にクローンされたmomongaを削除します。

[root@marmoset ~]# userdel -r momonga
設定の確認

rootでログインして下記のコマンドで設定が反映されていることを確認します。

[root@marmoset ~]# hostname
marmoset
[root@marmoset ~]# ip a | grep "inet "
    inet 127.0.0.1/8 scope host lo
    inet 10.0.2.130/24 brd 10.0.2.255 scope global noprefixroute enp0s3
    inet 192.168.56.130/24 brd 192.168.56.255 scope global noprefixroute enp0s8

鍵交換

既に作成済みの公開鍵をリモートホストに転送・設定します

MS-DOS
C:\Users\post>scp .ssh\id_ed25519.pub marmoset@192.168.56.130:/home/marmoset/
linux
// ユーザーをmarmosetに切り替え
[root@marmoset ~]# su - marmoset

// SSH関連ディレクトリ・ファイル作成
[marmoset@marmoset ~]$ mkdir .ssh
[marmoset@marmoset ~]$ chmod 700 .ssh
[marmoset@marmoset ~]$ touch .ssh/authorized_keys
[marmoset@marmoset ~]$ chmod 600 .ssh/authorized_keys

// 公開鍵登録
[marmoset@marmoset ~]$ cat id_ed25519.pug > .ssh/authorized_keys

// 不要なファイルを削除
[marmoset@marmoset ~]$ rm id_ed25519.pub

PuTTYでリモート接続

  1. PuTTY起動
  2. 「保存済みセッション一覧」からmomongaを選んで「読込」をクリック
  3. ホスト名を 192.168.56.130 に変更
  4. セッション名を marmoset に変更
  5. 左メニューの接続→データ、自動ログインのユーザ名: marmoset に変更
  6. 左メニューのセッションの「保存」をクリックして保存したら、「開く」をクリック
    パスワードなしでリモートホストにログイン出来たらOK

vscodeでリモート接続

configファイルに以下の設定を追加します。

Host marmoset
    HostName 192.168.56.130
    User marmoset
    IdentityFile C:\Users\post\.ssh\id_Ed25519
    Port 22
    TCPKeepAlive yes
    IdentitiesOnly yes
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?