Documenting the Process of Requesting Server Access at My New Company

2021/09/05

Preface

If you’ve read my previous posts, you probably know that I don’t like using third-party clients to connect to remote servers. I much prefer the built-in Terminal on macOS. As long as the authentication public key is configured on the remote server, I can conveniently connect with something like ssh xxx. At my previous company, server login was done entirely with key-based authentication, and password login was disabled. But since development and operations were integrated, I was managing the whole production environment and data cluster for the department, so I was also the one configuring public keys on the machines.

At my new company, the whole technical system is much more mature. We have a dedicated ops team, so naturally they won’t let you log into machines and configure your own public key. This way, permissions and passwords are fully isolated, login records on Linux can be audited, and once you leave the company, you can no longer access anything. Since the ops team also won’t allow direct root login, the process is a little different and the setup is a bit more cumbersome, but the underlying principle is the same, so I figured I’d write it down.

Process

Let me first walk through the whole process.

  1. Use your employee account to log into the internal SSO (our company’s internal server access request platform). The SSO generates a unique public key and a unique private key for you, and the private key is protected with a second layer of encryption.

  2. Then you apply for access to the server you need. Once approved, the ops team will create your username on the corresponding machine and place the public key generated by SSO into the authorized_keys file under your account. I assume this is all automated by scripts now.

  3. At that point, you already have permission to access the server. You just need to configure your local environment and you can log in directly.

    image-20210905232540664

My personal page on our company’s internal server access request platform


As long as the ops team has created your account and configured your public key on the server side (since the public key is generated by SSO, they can get it directly), you’re good to go. Because both the public key and private key are generated by SSO, you need to place the private key on your own computer (the client machine, using macOS as the default example here). Usually the downloaded private key file is named after your employee name; I’ve anonymized it here as othersKey.

The simplest approach is to rename the downloaded private key to id_rsa and put it under ~/.ssh. Since this is the system’s default private key, it will be used automatically every time you connect. Normally this key is generated with ssh-genkey, and you may already have the corresponding public key configured elsewhere.

Configuration

The best solution is to configure the host entry so it explicitly uses a specific key. In my earlier post on quick connection, I mentioned that you can configure shortcuts in etc/ssh/ssh_config. There’s actually another parameter there called IdentityFile that lets you specify which private key to use for a given connection, for example:

# The xxx in ssh xxx — in theory, just make it something easy to remember
Host nikeName
# Your server host
HostName 172.0.0.1
# Your default login username
User root
# Specify the private key path; default is ~/.ssh/id_rsa
IdentityFile ~/.ssh/othersKey
# Explained below
ForwardAgent yes 

There’s also a new property in the config above: ForwardAgent. I recommend enabling it, because environments vary from company to company, and most companies have a bastion host. In other words, the server you SSH into is often not the final target server.

Without agent forwarding, ops would need to store the public key on both the bastion host and the final server, and also store the private key on both your computer and the bastion host. That means your private key ends up being stored somewhere other than your local machine. Even though the bastion host definitely has access control policies in place, this still introduces a major security risk. If the bastion host gets compromised, the remaining remote servers are basically just sitting there waiting to be attacked. (That’s also why private keys are usually protected with a password: even if someone gets the private key, they still can’t do much without the passphrase.)

If you enable ForwardAgent, then only the public key needs to be stored on the bastion host and the target server. Since the public key is only used for decryption verification, it’s fine even if it gets exposed.

One more thing: private keys generated and distributed by companies usually come with a second verification password. When generating keys with ssh-genkey, I usually recommend just pressing Enter twice and leaving the passphrase empty by default. So when you use the company-issued private key to SSH into a server, you’ll typically see a prompt like Enter passphrase for key ~/.ssh/othersKey. image-20210905233033506

Prompt asking you to verify the private key passphrase


Then you need to enter the password provided on the page where you downloaded the private key. This is meant to prevent serious consequences if your private key is accidentally leaked. But doing this every single time is annoying, so you can have your computer remember the passphrase, which lets you use the private key without entering it again later.

Run ssh-add ~/.ssh/othersKey and it will prompt you for the passphrase. Just enter the password provided on the page. After that, it won’t ask you for the password again when you use this private key (it stops working after a reboot; see this post for the fix).

image-20210905233359609

And that’s it — the setup is done

Closing

Once you’ve configured it like this, you can just ssh xxx into the corresponding machine. Also, modifying etc/ssh/ssh_config is just my personal habit. ssh_config is the configuration file for the SSH client (the side initiating the connection), and changes there apply to all users on the system.

Your company wiki might instead recommend putting the config in ~/.ssh/config (if the config file doesn’t exist, just create it — the properties are written the same way). But that config file only takes effect for the macOS user account you’re currently logged into.

That’s pretty much it…

All articles in this blog, unless otherwise stated, are licensed under @Oreoft . Please indicate the source when reprinting!

Table of Contents