LoginSignup
1
1

More than 1 year has passed since last update.

Ubuntu20.04.3のセットアップ

Last updated at Posted at 2021-08-30

最近、開発環境をCentOSからUbuntuに切り替えているのでセットアップを行う機会が多くある。
自分なりのセットアップ手順をまとめた。

ホスト名の変更

初期設定のままだとわかりにくいので、以下のように変更する

root@vultr:~# hostnamectl set-hostname hoge
root@vultr:~# exit

一度、ログアウトし再度ログインすると、ホスト名が変更できているのが分かる

root@hoge:~# 

SSH

私はproxmoxにubuntuを入れて動かしているのでサーバーのIPアドレスを確認しSSHを行う。
サーバーにVNCが出来たら、初期設定にて設定したユーザー名とパスワードでログインを行う。
その後ip aを実行しサーバーのipを確認する。

image.png

1:loというのはループバックアドレスといって今回は利用しない。
2: ens18:が今回利用するアドレスだ。
inet 192.168.1.167/24となっているので、これにSSHを行う。

visudoを既定でvimで編集する

sudo update-alternatives --config editor

以下のように表示されるため、3番を選択する。vim.basicとvim.tinyではvim.basicを選択する。

There are 4 choices for the alternative editor (providing /usr/bin/editor).

  Selection    Path                Priority   Status
------------------------------------------------------------
* 0            /bin/nano            40        auto mode
  1            /bin/ed             -100       manual mode
  2            /bin/nano            40        manual mode
  3            /usr/bin/vim.basic   30        manual mode
  4            /usr/bin/vim.tiny    15        manual mode

ログインユーザーをパスワード無しでsudoを実行可とする

sudo visudo

25行目の# Allow members of group sudo to execute any commandの下に以下を追加する。
以下はパスワード無しでsudoを実行可とするユーザー名がubuntuの場合だ

ubuntu ALL=NOPASSWD: ALL

プロンプトの色を変更する

sudo -i
echo "export PS1='\[\033[01;32m\]\u@\h\[\033[00m\]:\[\033[01;34m\]\w\[\033[00m\]\$ '" >> /etc/profile.d/prompt.sh && \
echo "export PS1='\[\033[01;31m\]\u@\h\[\033[00m\]:\[\033[01;34m\]\w\[\033[00m\]\\$ '" >> /root/.bashrc

sshを公開鍵認証に変更

いくつか選択を求められるが、全てEnterでよい

ssh-keygen -t ed25519
cat .ssh/id_ed25519.pub >> ~/.ssh/authorized_keys
chmod 0700 ~/.ssh/ && chmod 0600 ~/.ssh/authorized_keys
sudo systemctl restart sshd

参考文献

visudoに関して @koara-local
https://qiita.com/koara-local/items/35b999631b6ab41fdc9f

sudo のパスワードを入力なしで使うには @RyodoTanaka
https://qiita.com/RyodoTanaka/items/e9b15d579d17651650b7

Centos8セットアップ(softetherセットアップ向け)-プロンプトの色を変更する @honahuku
https://qiita.com/honahuku/items/8d74833e649ccc511fdc#%E3%83%97%E3%83%AD%E3%83%B3%E3%83%97%E3%83%88%E3%81%AE%E8%89%B2%E3%82%92%E5%A4%89%E6%9B%B4%E3%81%99%E3%82%8B

1
1
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
1
1