LoginSignup
0
6

More than 5 years have passed since last update.

Linux リモートユーザー追加の手順メモ

Last updated at Posted at 2017-03-07

Amazon Linux にユーザーを追加したときのメモ

サーバー側作業

rootユーザーでユーザー追加

# useradd hogeuser

新規追加したユーザになり設定

# su - hogeuser
$ mkdir ~/.ssh
$ chmod 700 ~/.ssh

# 鍵の作成
$ ssh-keygen -t rsa
Generating public/private rsa key pair.
Enter file in which to save the key (/home/hogeuser/.ssh/id_rsa): (Enterで次へ)
Enter passphrase (empty for no passphrase): (パスフレーズ入力)
Enter same passphrase again: (パスフレーズ再入力)
Your identification has been saved in /home/hogeuser/.ssh/id_rsa.
Your public key has been saved in /home/hogeuser/.ssh/id_rsa.pub.

$ cd ~/.ssh
$ chmod 600 id_rsa.pub
$ mv id_rsa.pub authorized_keys
  • パスフレーズ無しでログインしたい場合はパスフレーズ入力は Enter のみ

クライアント作業

接続元のクライアントPCに秘密鍵をもっていってログインする準備

  • サーバーで作った秘密鍵(/home/hogeuser/.ssh/id_rsa)を接続元のクライアントPCに持って行く( 例:himitsu-hogeuser.pemとして保存する)
  • 保存した秘密鍵のパーミッションを変更する。
chmod 600 himitsu-hogeuser.pem

ログインしてみる

ssh -l hogeuser -i himitsu-hogeuser.pem (ログインしたいサーバーホスト or IPアドレス)
  • パスフレーズを入力した場合は、パスワードプロンプトが表示されるので鍵を作成する時に登録した パスフレーズを入力すればログインできる。 # 作成したユーザーがsudoユーザーとする
  • サーバー側にてrootユーザで作業
  • (例)以下の様な /etc/sudoers.d/hogeuserファイルをつくる
hogeuser ALL = NOPASSWD: ALL
  • ユーザー名を間違わないように注意!
  • /etc/sudoers.d/hogeuser のパーミッション/オーナー設定
chmod 440 /etc/sudoers.d/hogeuser
chown root:root /etc/sudoers.d/hogeuser
  • 以上です。
0
6
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
6