スポンサーリンク

CentOSにユーザーを追加する

ユーザーの作成とパスワード設定の2つの作業が必要になります。また必要に応じて管理者権限を付与してください。

スポンサーリンク

1. ユーザーを作成する

コマンド

useradd [ユーザー名]

< 実行例 >

$ sudo useradd user01
$ ◀ コマンド実行後なにも表示されなければ成功です

これでユーザーの作成は完了です。

2. パスワードを設定する

コマンド

passwd [ユーザー名]

< 実行例 >

$ sudo passwd user01
Changing password for user user01.
New password: ◀ パスワードをタイプ(表示されない)
Retype new password: ◀ 再度パスワードをタイプ(表示されない)
passwd: all authentication tokens updated successfully.
$

これでパスワードの設定は完了です。

補足1. sudo権限の付与

/etc/sudoers を編集します。

コマンド

visudo

< 実行例 >

$ sudo visudo

コマンドを実行すると /etc/sudoers ファイルが開くので、水色の部分を追記して保存します。

## Next comes the main part: which users can run what software on
## which machines (the sudoers file can be shared between multiple
## systems).
## Syntax:
##
##      user    MACHINE=COMMANDS
##
## The COMMANDS section may have other options added to it.
##
## Allow root to run any commands anywhere
root    ALL=(ALL)       ALL
user01    ALL=(ALL)       ALL

## Allows members of the 'sys' group to run networking, software,
## service management apps and more.
# %sys ALL = NETWORKING, SOFTWARE, SERVICES, STORAGE, DELEGATING, PROCESSES, LOCATE, DRIVERS

## Allows people in group wheel to run all commands
%wheel  ALL=(ALL)       ALL

## Same thing without a password
# %wheel        ALL=(ALL)       NOPASSWD: ALL

## Allows members of the users group to mount and unmount the
## cdrom as root
# %users  ALL=/sbin/mount /mnt/cdrom, /sbin/umount /mnt/cdrom

## Allows members of the users group to shutdown this system
# %users  localhost=/sbin/shutdown -h now

補足2. パスワードでログインできるようにする

初期設定でパスワードによるログインが無効化されており、ログインできない場合あります。その場合は /etc/ssh/sshd_config を編集し、パスワードを使ったログインを有効化します。

$ sudo vi /etc/ssh/sshd_config

PasswordAuthentication yes のコメントアウト (#) を解除し、PasswordAuthentication no をコメントアウトします。

< 変更前 >

<略>
# To disable tunneled clear text passwords, change to no here!
#PasswordAuthentication yes
#PermitEmptyPasswords no
PasswordAuthentication no

# Change to no to disable s/key passwords
#ChallengeResponseAuthentication yes
ChallengeResponseAuthentication no
<略>

< 変更後 >

<略>
# To disable tunneled clear text passwords, change to no here!
PasswordAuthentication yes
#PermitEmptyPasswords no
#PasswordAuthentication no

# Change to no to disable s/key passwords
#ChallengeResponseAuthentication yes
ChallengeResponseAuthentication no
<略>

変更後に sshd を再起動して変更を反映させます。

$ sudo systemctl restart sshd

以上。

コメント

タイトルとURLをコピーしました