# User Configuration

## Create a Non-Root User

As the `root` user, create a non-root user for deployments and add that user to the `sudo` group using the following commands:

```bash
useradd <USERNAME>
```

```bash
usermod -aG sudo <USERNAME>
```

The home directory for the non-root user is located at `/home/<USERNAME>`.

To later connect to the non-root user via SSH, you'll need to add your SSH key to the user. This can be done while logged in as the `root` user using the following command:

```bash
rsync -a --chown=<USERNAME>: ~/.ssh /home/<USERNAME>
```

If necessary, while logged in as the `root` user, you can switch to the non-root user using the following command:

```bash
su - <USERNAME>
```

You can switch back to the `root` user by typing `exit`.

{% hint style="info" %}
The rest of the commands in the **User Configuration** section should be run as the non-root user.
{% endhint %}

## Git

Configure Git using the following commands:

```bash
git config --global user.name "<NAME>"
```

```bash
git config --global user.email "<EMAIL>"
```

Create an SSH key for the non-root user in order to access GitHub, etc.:

```bash
ssh-keygen
```

As mentioned above, you can print out the non-root user's SSH key by using the following command:

```bash
cat ~/.ssh/id_rsa.pub
```

## Ruby and Bundler

Install Ruby 2.6.5 and Bundler using the following commands inside the non-root user's home directory:

```bash
git clone https://github.com/rbenv/rbenv.git ~/.rbenv
```

```bash
git clone https://github.com/rbenv/ruby-build.git ~/.rbenv/plugins/ruby-build
```

```bash
echo 'export PATH="$HOME/.rbenv/bin:$PATH"' >> ~/.bashrc
```

```bash
echo 'export PATH="$HOME/.rbenv/plugins/ruby-build/bin:$PATH"' >> ~/.bashrc
```

```bash
echo 'eval "$(rbenv init -)"' >> ~/.bashrc
```

```bash
exec $SHELL
```

```bash
rbenv install 2.6.5
```

```bash
rbenv global 2.6.5
```

```bash
gem install bundler
```

```bash
rbenv rehash
```

You can check the current version of Ruby using the following command:

```bash
rbenv version
```

List all installed versions of Ruby:

```bash
rbenv versions
```

Change the version of Ruby:

```bash
rbenv global <VERSION>
```


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.alistairtweed.com/rails/manually-deploying-a-rails-6-application-on-ubuntu-18.04-digitalocean/user-configuration.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
