LoginSignup
3
3

More than 5 years have passed since last update.

Ansibleでユーザ追加してからsshログイン

Last updated at Posted at 2015-05-16

simple-playbook.ymlは下のような書き方で wangというユーザを追加したあとにそのユーザに対して、sshのパブリック鍵でログインできるようにする

---
- hosts: all
  sudo: true
  vars:
    # パスワードをハッシュ化
    # $ openssl passwd -salt 123 -1 p@ssW0rd
    password : ((23$Ms8m3027INiL/x4hBcH3c1))
    user : wang

  tasks:
    - name: create a normal user
      user:
        name={{user}}
        password={{password}}
        state=present
        group="root"
        shell=/usr/bin/bash
    - name: Set up authorized_keys for the normal user
      authorized_key:
        user={{user}}
        # ローカルのパブリック鍵を指定する
        key="{{ lookup('file', '/Users/wang/.ssh/id_rsa.pub') }}"

参照リンク:
http://docs.ansible.com/authorized_key_module.html

3
3
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
3
3