9
11

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

Ubuntuのホスト名/ユーザ名変更

Posted at

Ubuntuのホスト名変更

  • hostname コマンドでホスト名を確認します。

user01@ino-ubuntu1:/home$ hostname
ino-ubuntu1

  • hostnamectl set-hostname [hostname] コマンドでホスト名を変更します。
  • 「ino-ubuntu1」を「ino-ubuntu」に変更します。(地味な変更w)

user01@ino-ubuntu1:/home$ hostnamectl set-hostname ino-ubuntu
==== AUTHENTICATING FOR org.freedesktop.hostname1.set-static-hostname ===
Authentication is required to set the statically configured local host name, as well as the pretty host name.
Multiple identities can be used for authentication:

  1. ,,, (user01)
  2. ojima,,, (ojima)
    Choose identity to authenticate as (1-2): 2
    Password:
    ==== AUTHENTICATION COMPLETE ===
    user01@ino-ubuntu1:/home$
  • 確認します。

user01@ino-ubuntu1:/home$ hostnamectl
Static hostname: ino-ubuntu
Icon name: computer-vm
Chassis: vm
Boot ID: 1e9f1c85a8d24442aba6b5ea14adb5ac
Operating System: Ubuntu 14.04 LTS
Kernel: Linux 3.13.0-24-generic
Architecture: x86_64
user01@ino-ubuntu1:/home$

  • 再起動します。

user01@ino-ubuntu1:/home$ sudo reboot
user01@ino-ubuntu1:/home$ sudo reboot
sudo: unable to resolve host ino-ubuntu
user01@ino-ubuntu1:/home$
Broadcast message from user01@ino-ubuntu
(/dev/pts/0) at 12:36 ...

The system is going down for reboot NOW!

  • 変更されました!

ojima@ino-ubuntu:~$

[参考]
https://www.server-world.info/query?os=Ubuntu_16.04&p=hostname

Ubuntuのユーザ名変更

  • usermod -l [new] [old] コマンドでユーザ名Renameします。
  • ユーザ名「ojima」を「inohana」に変更します。

ojima@ino-ubuntu:~$ usermod -l inohana ojima
usermod: user ino is currently used by process 1461

  • エラー勃発w プロセスをKillします。

ojima@ino-ubuntu:~$ kill -3 1461
ojima@ino-ubuntu:~$ sudo usermod -l inohana ojima
[sudo] password for ojima:
usermod: user ojima is currently used by process 1747
ojima@ino-ubuntu:~$ sudo kill -3 1747

  • うまくいかないので再起動。。。

ojima@ino-ubuntu:~$ sudo reboot
sudo: unable to resolve host ino-ubuntu
[sudo] password for ojima:
ojima@ino-ubuntu:~$
Broadcast message from ojima@ino-ubuntu
(/dev/pts/0) at 12:58 ...

The system is going down for reboot NOW!

  • 上記繰り返してようやく成功しました。(結局別ユーザ名から実行しました。)

user01@ino-ubuntu:~$ sudo usermod -l inohana ojima
[sudo] password for user01:
usermod: user ojima is currently used by process 1446
user01@ino-ubuntu:~$ kill -3 1446
-bash: kill: (1446) - Operation not permitted
user01@ino-ubuntu:~$ sudo kill -3 1446
user01@ino-ubuntu:~$ sudo usermod -l inohana ojima
user01@ino-ubuntu:~$

  • 成功しました。

inohana@ino-ubuntu:~$

inohana@ino-ubuntu:~$ cd /home
inohana@ino-ubuntu:/home$ ls
total 16
drwxr-xr-x 4 root root 4096 Jan 6 07:55 .
drwxr-xr-x 23 root root 4096 Jan 6 08:55 ..
drwxr-xr-x 7 inohana ojima 4096 Mar 1 12:17 ojima
drwxr-xr-x 5 user01 user01 4096 Mar 1 11:55 user01

inohana@ino-ubuntu:/home$ mv ojima/ inohana/
inohana@ino-ubuntu:/home$ ls
total 16
drwxr-xr-x 4 root root 4096 Mar 1 13:10 .
drwxr-xr-x 23 root root 4096 Jan 6 08:55 ..
drwxr-xr-x 3 root root 4096 Mar 1 13:15 inohana
drwxr-xr-x 5 user01 user01 4096 Mar 1 11:55 user01

  • パスワードのバックアップ。

inohana@ino-ubuntu:/home$ sudo cp -a /etc/passwd /etc/passwd.bk

  • 中身の確認。

inohana@ino-ubuntu:/home$ cat /etc/passwd
<略>
inohana: x :1000:1000:ojima,,,:/home/ojima:/bin/bash
inohana@ino-ubuntu:/home$

  • 修正後。
    inohana: x :1000:1000:inohana,,,:/home/inohana:/bin/bash
  • グループのバックアップ。

inohana@ino-ubuntu:/home$ sudo cp -a /etc/group /etc/group.bk

  • 旧ユーザ名部分を新ユーザ名に変更。
    inohana@ino-ubuntu:/home$ sudo vim /etc/group

以上。

[参考]
http://ta1se1.hatenablog.com/entry/usermod_error

9
11
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
9
11

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?