Skip to content

Instantly share code, notes, and snippets.

@ProbablePrime
Last active August 13, 2017 20:06
Show Gist options
  • Save ProbablePrime/ddbbd3571c512d0ed4b7f9f994cb2a1e to your computer and use it in GitHub Desktop.
Save ProbablePrime/ddbbd3571c512d0ed4b7f9f994cb2a1e to your computer and use it in GitHub Desktop.
Provisioning a new user on an Ubuntu Machine manually.

While experimenting with Ubuntu on a variet of systems I often need to stand up a brand new machine and secure access to it. A lot of providers will setup the machine using the root account and email you a password. I'd rather not use the root user and setup RSA Keys. Doing this manually is a bit of a chore but if you don't have any other options here's how to do it.

1 Create User

  1. Use adduser to do this quickly.
  2. Run adduser <username>.
  3. Enter a new password twice, Remember this needed for sudo.

2 Create User SSH Config

This is the section i always forget, I'll usually spend half an hour googling for the chmod settings required.

  1. su <username>
  2. Create .ssh Folder and authorized keys file
mkdir ~/.ssh
touch ~/.ssh/authorized_keys
chmod 700 ~/.ssh
chmod 600 ~/.ssh/authorized_keys
  1. Add a public key to authorized_keys. This is one line per public key. Check it very carefully. Misspastes or typos can lock you out. ssh-copy-id <username>@<host> can be used from Unix machines. I use windows.

3 Setup SSH Config

  1. In /etc/ssh/sshd_config
PubkeyAuthentication yes
AuthorizedKeysFile      .ssh/authorized_keys .ssh/authorized_keys2

Add New User to Sudo Group (Optional)

usermod -a -G sudo <username>

Disable Root Login (Optional)

  1. In /etc/ssh/sshd_config
PermitRootLogin no

Disable Password Auth (Optional)

  1. In /etc/ssh/sshd_config
PasswordAuthentication no

Further Work

  1. Automate this Options:
    • CloudConfig
    • Chef / Puppet
    • Ansible
    • iPXE

References

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment