LoginSignup
0
1

More than 3 years have passed since last update.

サーバーにユーザーを登録する方法

Last updated at Posted at 2019-05-27

サーバーにユーザーを登録

まずはsshでサーバーに入ります(省略)。

ターミナル
[ユーザー名@pub2 ~]$  sudo useradd -G ocw,wheel [新しいユーザー名]
あなたはシステム管理者から通常の講習を受けたはずです。
これは通常、以下の3点に要約されます:

    #1) 他人のプライバシーを尊重すること。
    #2) タイプする前に考えること。
    #3) 大いなる力には大いなる責任が伴うこと
[sudo] ユーザー名 のパスワード:
[ユーザー名@pub2 ~]$ sudo passwd [新しいユーザー名]
ユーザー [新しいユーザー名] のパスワードを変更。
新しいパスワード:
passwd: すべての認証トークンが正しく更新できました。

次に/home/[新しいユーザー名]/.ssh/authorized_keysにsshの公開鍵をおきます

ターミナル
[ユーザー名@pub2 ~]$ sudo mkdir /home/[新しいユーザー名]/.ssh
[ユーザー名@pub2 ~]$ sudo cat > /home/[新しいユーザー名]/.ssh/authorized_keys
-bash: /home/[新しいユーザー名]/.ssh/authorized_keys: 許可がありません
[ユーザー名@pub2 ~]$ sudo su  #権限がないのでスーパーユーザーへ
[root@pub2 ユーザー名]#  sudo cat > /home/[新しいユーザー名]/.ssh/authorized_keys
  #catでそのまま書き込みます.
以下、公開鍵。
ssh-rsa ............................................
[root@pub2 ユーザー名]# cd /home/[新しいユーザー名]/
[root@pub2 [新しいユーザー名]]# ls -la
合計 20
drwx------.  3 [新しいユーザー名] [新しいユーザー名]   83  5月 27 18:45 .
drwxr-xr-x. 15 root      root      4096  5月 27 18:39 ..
-rw-r--r--.  1 [新しいユーザー名] [新しいユーザー名]   18 10月 31  2018 .bash_logout
-rw-r--r--.  1 [新しいユーザー名] [新しいユーザー名]  193 10月 31  2018 .bash_profile
-rw-r--r--.  1 [新しいユーザー名] [新しいユーザー名]  231 10月 31  2018 .bashrc
-rw-r--r--.  1 [新しいユーザー名] [新しいユーザー名]  334 10月 30  2018 .emacs
drwxr-xr-x.  2 root      root        28  5月 27 18:48 .ssh

[root@pub2 [新しいユーザー名]]# sudo chown [新しいユーザー名]. -R /home/[新しいユーザー名]/.ssh  

[root@pub2 [新しいユーザー名]]# ls -la
合計 20
drwx------.  3 [新しいユーザー名] [新しいユーザー名]   83  5月 27 18:45 .
drwxr-xr-x. 15 root      root      4096  5月 27 18:39 ..
-rw-r--r--.  1 [新しいユーザー名] [新しいユーザー名]   18 10月 31  2018 .bash_logout
-rw-r--r--.  1 [新しいユーザー名] [新しいユーザー名]  193 10月 31  2018 .bash_profile
-rw-r--r--.  1 [新しいユーザー名] [新しいユーザー名]  231 10月 31  2018 .bashrc
-rw-r--r--.  1 [新しいユーザー名] [新しいユーザー名]  334 10月 30  2018 .emacs
drwxr-xr-x.  2 [新しいユーザー名]  [新しいユーザー名]  28  5月 27 18:48 .ssh 
#権限が変わってますね。 

登録したユーザーに権限(諸々)をあげる

ターミナル
[root@pub2 [新しいユーザー名]]#  sudo chmod 0700 /home/[新しいユーザー名]/.ssh/
[root@pub2 [新しいユーザー名]]#  sudo chmod 0600 /home/[新しいユーザー名]/.ssh/authorized_keys 
[root@pub2 [新しいユーザー名]]# ls -la .ssh
合計 4
drwx------. 2 [新しいユーザー名] [新しいユーザー名]  28  5月 27 18:48 .
drwx------. 3 [新しいユーザー名] [新しいユーザー名]  83  5月 27 18:45 ..
-rw-------. 1 [新しいユーザー名] [新しいユーザー名] 729  5月 27 18:48 authorized_keys

一番左にある、rはread,wはwriteとそれぞれのできることで、どのユーザーがなんの権利があるかをみることができます。

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