LoginSignup
36
56

More than 5 years have passed since last update.

Raspbianでpiユーザ名とパスワードをうまいこと変更する

Last updated at Posted at 2018-02-24

Raspbianのセットアップでユーザ名とパスワードを変更するための手順をまとめました。

いつもはpiユーザを削除したり新しいユーザを作成してましたが、
piユーザを変更する方法が良いという記事を見かけましたので、
そちらの方式をやってみたいと思います。

実行環境

$ lsb_release -a
Distributor ID: Raspbian
Description:    Raspbian GNU/Linux 9.3 (stretch)
Release:        9.3
Codename:       stretch

ここからはすべてSSH接続で作業します。

piユーザ情報

初期設定時のユーザIDとパスワード

User: pi
Pass: raspberry

tmpユーザを作成

$ sudo useradd -M tmp
$ sudo gpasswd -a tmp sudo
Adding user tmp to group sudo
$ sudo passwd tmp
Enter new UNIX password:
Retype new UNIX password:
passwd: password updated successfully

自動ログインユーザの変更

2ファイル変更します。

$ sudo vim /etc/lightdm/lightdm.conf
/etc/lightdm/lightdm.conf
autologin-user=pi
↓ 
# autologin-user=pi
$ sudo vim /etc/systemd/system/autologin@.service 
/etc/systemd/system/autologin@.service
ExecStart=-/sbin/agetty --autologin pi --noclear %I $TERM
↓ piをtmpに変更
ExecStart=-/sbin/agetty --autologin tmp --noclear %I $TERM

変更したら再起動します。

$ sudo reboot

tmpユーザでログインしてpiユーザ名変更

tmpユーザしかいないことを確認

$ who
tmp      tty1         2018-02-24 01:07
tmp      pts/0        2018-02-24 01:08 (192.168.1.4)

piユーザ名を変更する

piユーザ名を変更する(例:newpi)
$ sudo usermod -l newpi pi

$ sudo usermod -l newpi pi

We trust you have received the usual lecture from the local System
Administrator. It usually boils down to these three things:

    #1) Respect the privacy of others.
    #2) Think before you type.
    #3) With great power comes great responsibility.

[sudo] password for tmp:
$

usermod と groupmod を変更する

$ sudo usermod -d /home/newpi -m newpi
$ sudo groupmod -n newpi pi

変更したら再起動します。

$ sudo reboot

newpiでログインしてnewpiのパスワードを変更

$ sudo passwd newpi
We trust you have received the usual lecture from the local System
Administrator. It usually boils down to these three things:

    #1) Respect the privacy of others.
    #2) Think before you type.
    #3) With great power comes great responsibility.

[sudo] password for newpi:
Enter new UNIX password:
Retype new UNIX password:
passwd: password updated successfully

自動ログインユーザの変更

tmpをnewpiに変更します。

$ sudo vim /etc/systemd/system/autologin@.service 
/etc/systemd/system/autologin@.service
ExecStart=-/sbin/agetty --autologin tmp --noclear %I $TERM
↓
ExecStart=-/sbin/agetty --autologin newpi --noclear %I $TERM

変更したら再起動します。

$ sudo reboot

tmpユーザを削除

$ sudo userdel tmp
[sudo] password for newpi:
$

参考資料

[Raspbian]ユーザ名変更の個人的に「正しい」と思うやり方
Raspberry Pi3(ラズパイ)でpiユーザーの自動ログインを外す方法

36
56
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
36
56