A separate administrator: from key login to the right privileges

Account identity, key login, and privilege escalation require separate checks.

A small key with a ribbon apart from a large key: separating everyday access from full access.
A small key with a ribbon apart from a large key: separating everyday access from full access.

Working as root all the time combines routine actions with unrestricted system privileges. A mistaken command immediately has the same reach as an intentional administrative change. A separate account makes privilege escalation an explicit action.

A new username alone, however, does not create safe access. It needs a clear owner, verified login, appropriate privileges, and recovery if the primary route fails. For Solution200’s server foundation, this is a separate task before restricting root over SSH.

E-01 practice: creating the administrator and opening a fresh session

The training Debian 13 server had no separate regular user, and sudo was already installed. I created solution200 for administration. On the workstation, I prepared a dedicated Ed25519 key protected by a passphrase and loaded it into a separate SSH agent. The private key stayed on the workstation; I sent its public half to the server to configure key-based access.

I ran the commands below as root. The install command with /dev/stdin as its source received the public key through the SSH session’s standard input, keeping its contents out of the command line. These are separate steps with prepared input, rather than a script to paste without checking:

adduser --disabled-password --comment "" solution200
install -d -m 0700 -o solution200 -g solution200 /home/solution200/.ssh
install -m 0600 -o solution200 -g solution200 /dev/stdin /home/solution200/.ssh/authorized_keys
adduser solution200 sudo

--disabled-password skips setting a password while creating the user; it does not permanently prohibit password access. I set a separate OS password using chpasswd, supplying the data through protected standard input. This password serves normal sudo authentication and differs from the key’s passphrase.

The system assigned UID and primary GID 1000; I did not specify the number manually. After adding the account to the sudo group, I opened a fresh independent SSH connection using the selected key. The client used BatchMode=yes, IdentitiesOnly=yes, and PreferredAuthentications=publickey; password and keyboard-interactive fallback were disabled. Strict host-key verification remained enabled. These OpenSSH client settings help isolate the chosen key from other authentication methods.

hostname
id -un
id
stat -c '%a %U:%G %n' ~/.ssh ~/.ssh/authorized_keys

hostname returned article-solution200-demo, and id -un returned solution200. The account belonged to the sudo and users groups. The .ssh directory had mode 700 and authorized_keys had mode 600; both belonged to the new account and its primary group. The screenshot shows verification repeated after setup:

Unauthenticated rejection and actual privilege elevation

I first invalidated the sudo cache and tried running without a password prompt:

sudo -k
sudo -n -- id -u

The result was sudo: a password is required with exit code 1. I then supplied the new user’s password to sudo -S through protected stdin, listed the permissions, and ran a command with elevated privileges:

sudo -S -p '' -v
sudo -n -l
sudo -n -- id -u
sudo -k

sudo -n -l listed (ALL : ALL) ALL, and sudo -n -- id -u returned 0. This is a full system administrator with password authentication before privilege elevation. The final sudo -k cleared the authentication cache.

Root access and the open Mirohost VNC console remained available. I did not change sshd policy in this step: a successful key-based administrator session does not itself disable password-based SSH. Restricting the existing access path is a separate next change.

Define the role before creating the account

A system administrator and an application’s runtime user have different jobs. A web process should not gain administrative SSH access simply because its files live on the server. For a person, define the operations they perform and how their privileges can be revoked.

On Debian, adduser supports creating ordinary accounts. Choose names, groups, and authentication for the environment. The hypothetical ops-demo user here is not an existing platform account.

Membership of sudo can grant very broad privileges. This is a convenient full-administrator model, but it is not automatically least privilege. A restricted policy needs analysis of allowed programs, arguments, and whether those programs can open a shell or modify privileged files.

The public key goes to the server

Send the public key to the server. Keep the private key under the user’s control; a passphrase reduces the consequences of theft of its file, while still requiring careful handling of the agent and backup.

OpenSSH must find the key in an allowed source and accept it under the configuration. File ownership, home-directory and SSH-file permissions, account restrictions, and server rules all matter. The sshd manual describes authorized_keys and file-access checks.

Copying a key does not prove login works. Open a new session from the intended client and establish the actual authentication method. Otherwise a successful login might silently have used a password or a different agent key.

Check privilege escalation separately

After login, a hypothetical administrator can begin with:

id
sudo -l
sudo -v

Run these only in an authorised environment. id shows the current identity and groups; new group membership may require a fresh session. The sudo manual explains that -l lists permissions, while -v validates credentials and refreshes their caching without running a command. Neither is equivalent to performing the required administrative operation.

Next, safely test a specific permitted action, such as reading a chosen service’s status with the required privileges. Test rejection of an unnecessary action using a controlled example that cannot damage production data.

Stage What it establishes
The account exists The system recognises the identity
A new session uses the intended key The defined login route works
Reviewing sudo policy Declared privileges are visible
A permitted administrative action The required practical scenario works
Checking an unnecessary action The defined boundary actually restricts access

Distinguish three kinds of secrets

An OS account password, a private-key passphrase, and a password sudo may request belong to different checks. Configuration can connect them, but they are not one setting. Changing a key file’s passphrase does not revoke its authorised public key on the server. Revoking a key does not necessarily remove another configured login method for that account.

When preparing access, record the permitted methods. A hypothetical administrator may successfully log in by key while privilege escalation requires local authentication under sudo policy. Verify that before disabling the old route. Otherwise the first success conceals a second unfinished task.

For restricted sudo access, review the allowed command’s behaviour. An editor, interpreter, or tool that can launch other programs may provide more capability than its name suggests. A command list alone does not establish a narrow policy without examining that behaviour.

Transfer and terminate access

The owner of a single-author journal may perform several roles, but technical boundaries remain useful. An administrative session, web process, and background consumer should not silently become one user with identical privileges. Separation makes each task’s access requirements explainable.

When replacing a device, maintain an inventory of authorised keys and their owners. A public-key comment can aid navigation but does not itself prove a person’s identity. After revocation, check the lost login route specifically, not merely the presence of a new key.

Consider already open sessions separately: changing permission for future login does not always end a current connection. Termination depends on the event and chosen procedure, so understand it before an incident. Account maintenance then covers creation, use, and termination of access.

Keep the old route until the new one works

Retain the current administrative session until the new user passes independent login and the necessary privilege checks. Also prepare a recovery console that does not depend on the same SSH settings.

For ongoing maintenance, record the key owner, purpose, and revocation procedure. A lost device or changed responsibility requires removing the corresponding access, not merely changing another account’s password.

A separate administrator is useful when every link is clear: who logs in, how they authenticate, when they elevate privileges, and how control can be recovered. Restricting root becomes the next change only after verifying that chain.

  1. Operations & Security Your first SSH login: recognising your server
  2. Operations & Security When to restrict root and password-based SSH
  3. Operations & Security Recovering VPS access when SSH stops working
  4. Operations & Security Planned SSH key rotation: verifying new access and revoking the old key

A project by the author · Weather Solution200

After reading, a look outside.

Temperature, rain and wind in your city. Check the forecast and plan the hours ahead.

Check the forecast
Next article