LoginSignup
0
0

More than 1 year has passed since last update.

Mac/VagrantでAlmaLinux8をインストールしてみる

Last updated at Posted at 2021-07-06

概要

CentOS 8が2021年で開発を打ち切ると発表されたため、その後継となる「AlmaLinux」をVagrantでインストールしてみました

環境

PC: Macbook Pro
OS: MacOS Catalina

1. Vagrantの初期化

任意のフォルダを作成し、vagrant initを実行する

user$> mkdir sample01
user$> cd sample01
user$> vagrant init
A `Vagrantfile` has been placed in this directory. You are now
ready to `vagrant up` your first virtual environment! Please read
the comments in the Vagrantfile as well as documentation on
`vagrantup.com` for more information on using Vagrant.

2. Vagrantfileを修正する

Vagrant.configure("2") do |config|

  config.ssh.insert_key = false

  config.vm.define "AlmaLinux8" do |al8|
    al8.vm.box = "almalinux/8"
    al8.vm.network :private_network, ip: "192.168.10.2"
  end

  config.vm.provider "virtualbox" do |vb|
    vb.gui = false
    vb.name = "AlmaLinux8"
    vb.customize ["modifyvm", :id, "--audio", "none"]
  end

end

他のBoxをインストールしたい場合は下記サイトから探して見てください
https://app.vagrantup.com/boxes/search

3. Vagrantfileがあるフォルダでvagrant upを実行する

user$> vagrant up
Bringing machine 'AlmaLinux8' up with 'virtualbox' provider...
・・・・・
==> AlmaLinux8: Mounting shared folders...
    AlmaLinux8: /vagrant => /sample01

4. サーバーにsshでログインしてみる

user$> vagrant ssh
[vagrant@localhost ~]$ ←ログインできればこういう表示になります
[vagrant@localhost ~]$ sudo su -
[root@localhost ~]$ ←rootユーザーになる

5. 後々面倒なので、Selinuxを停止しておきます

[root@localhost ~]$ setenforce 0
[root@localhost ~]$ vi /etc/selinux/config
SELINUX=enabled → 【disabled】に変更

6. yumをアップデートする

vagrantのboxからインストールした状態では、各種パッケージが古い状態なのでyumコマンドで一括アップデートを行う

[root@localhost ~]$ yum -y update

7. タイムゾーンを設定

インストール直後はタイムゾーンがUTCになっているので、日本時間に変更する

[root@localhost ~]# date
Tue Jul  6 08:24:12 UTC 2021
[root@localhost ~]# timedatectl set-timezone Asia/Tokyo
[root@localhost ~]# systemctl restart rsyslog.service
[root@localhost ~]# date
Tue Jul  6 17:25:26 JST 2021

8. ホスト名を変更する

これは別にやる必要はないけど、なんとなくサーバー感が出るのと複数のVMを立ち上げるとホスト名で判断したりするので設定する

[root@localhost ~]# hostname sample01.test.jp
[root@localhost ~]# hostnamectl set-hostname sample01.test.jp

9. SSH公開鍵認証設定

個別ユーザーを作成し、SSH鍵でログインできるように設定する

9-1. sshの設定から公開鍵認証を有効化する

[root@localhost ~]# vi /etc/ssh/sshd_config
#PubkeyAuthentication yes
 ↓
PubkeyAuthentication yes
[root@localhost ~]# systemctl restart sshd.service

9-2. 個別ユーザーを追加する

[root@localhost ~]# useradd testuser

9-3. ホストPCでSSH鍵を生成する

user$> ssh-keygen -t rsa -b 4096
user$> cd ~/.ssh
user$> ls -lah
-rw-------@  1 user  xxxxxxxxx   1.8K  7  1 16:33 id_rsa
-rw-------@  1 user  xxxxxxxxx   405B  7  1 16:33 id_rsa.pub

9-4. ゲストPCで作成した公開鍵情報を登録する

[root@localhost ~]# cd /home/testuser
[root@localhost ~]# mkdir .ssh
[root@localhost ~]# chmod 700 .ssh
[root@localhost ~]# vi .ssh/authorized_keys    # ホストPCにある公開鍵情報を貼り付ける
[root@localhost ~]# chmod 600 .ssh/authorized_keys
[root@localhost ~]# chown -R testuser:testuser .ssh

9-5. ホストPCからログインしてみる

user$> ssh testuser@192.168.10.2

9-6. sudoコマンドでパスワード聞かれないようにする

[root@localhost ~]# visudo
## Same thing without a password
# %wheel        ALL=(ALL)       NOPASSWD: ALL
testuser        ALL=NOPASSWD: ALL
[testuser@localhost ~]# sudo su -
※パスワード聞かれずにrootユーザーになれればOK
0
0
1

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