Skip to content

Task: Access & secrets

SSH, kube contexts, cloud logins, registry auth, Vault and cloud secret stores.

IndexUpdated

Also:access · login · credentials · secrets · kubeconfig · ssh · auth · permission denied · unauthorized

Commands tagged caution here print secrets to the terminal. Avoid them while screen sharing.

28 items

Linux2

Linux: SSH into a host with a specific key

Safe

Connect using one explicit key (avoids 'Too many authentication failures').

ssh -i <key-file> -o IdentitiesOnly=yes <user>@<host>
What each part does
  1. sshSSH client
  2. -i <key-file>use this private key
  3. -o IdentitiesOnly=yesoffer only that key, not every key in the agent (avoids Too many authentication failures)
  4. <user>@<host>who and where

Also known as: ssh · Too many authentication failures · permission denied (publickey)

Tool page →

Linux: Open an SSH tunnel through a bastion

Safe

Forward a local port to a private host/port via a jump box. Then connect to localhost:<local-port>.

ssh -N -L <local-port>:<target-host>:<target-port> <user>@<bastion>
What each part does
  1. sshSSH client
  2. -Ndon't run a remote command: tunnel only
  3. -L <local-port>:<target-host>:<target-port>localhost:local-port forwards to target-host:target-port as seen from the bastion
  4. <user>@<bastion>the jump host to connect to
Example
$ ssh -N -L 5432:db.internal:5432 ops@bastion.example.com

Also known as: port forward · bastion · jump host · ssh tunnel

Tool page →

Git1

Git: Use a specific SSH key for one repo

Safe

Per-repo SSH key, handy for multiple GitHub accounts.

git config core.sshCommand "ssh -i <key-file> -o IdentitiesOnly=yes"
What each part does
  1. git configset a repo-local setting (stored in .git/config)
  2. core.sshCommandthe ssh command git uses for this repo
  3. ssh -i <key-file>use this private key
  4. -o IdentitiesOnly=yesdon't also offer agent keys (avoids authenticating as the wrong account)

Also known as: multiple github accounts · permission denied (publickey)

Tool page →

Docker2

Docker: Open a shell inside a container

Safe

Interactive shell in a running container. Use bash if the image has it.

docker exec -it <container> sh
What each part does
  1. docker execrun a command in a running container
  2. -itinteractive + allocate a terminal
  3. <container>container name or ID
  4. shthe shell to start; use bash if the image has it

Also known as: docker exec · shell into container

Tool page →

Docker: Log in to a registry without leaking the password

Safe

Pipe the token in so it never shows up in shell history or ps.

echo "$REGISTRY_TOKEN" | docker login <registry> -u <username> --password-stdin
What each part does
  1. echo "$REGISTRY_TOKEN"print the token from an env var (not typed on the command line)
  2. |pipe it into the next command's stdin
  3. docker login <registry>authenticate to the registry
  4. -u <username>the user name
  5. --password-stdinread the password from stdin, so it stays out of shell history and ps

Also known as: docker login · unauthorized: authentication required

Tool page →

Podman1

Podman: Log in to a registry

Safe

Store registry credentials for pulls and pushes (auth.json).

podman login <registry> -u <username>
What each part does
  1. podman login <registry>authenticate to a registry, e.g. quay.io
  2. -u <username>the user name; prompts for the password (or use --password-stdin)

Also known as: podman login · unauthorized

Tool page →

Kubernetes4

Kubernetes: Exec into a pod

Safe

Interactive shell inside the pod's (first) container.

kubectl exec -it <pod> -n <namespace> -- sh
What each part does
  1. kubectl execrun a command in a container of a running pod
  2. -itinteractive + terminal
  3. <pod>the pod (add -c <container> if it has several)
  4. -n <namespace>namespace of the pod
  5. -- sheverything after -- is the command to run; use bash if the image has it

Also known as: kubectl exec · shell into pod

Tool page →

Kubernetes: Port-forward to a service

Safe

Reach a ClusterIP service from your laptop on localhost:<local-port>.

kubectl port-forward svc/<service> <local-port>:<remote-port> -n <namespace>
What each part does
  1. kubectl port-forwardtunnel a local port to a pod through the API server
  2. svc/<service>pick a pod behind this service
  3. <local-port>:<remote-port>listen locally on the first, forward to the second
  4. -n <namespace>namespace of the service
Example
$ kubectl port-forward svc/prometheus-operated 9090:9090 -n monitoring
# then open http://localhost:9090

Also known as: port forward · kubectl port-forward · prometheus ui · grafana ui

Tool page →

Kubernetes: Switch kubeconfig context

Safe

Point kubectl at another cluster. List them with kubectl config get-contexts.

kubectl config use-context <context>
What each part does
  1. kubectl config use-contextmake a context current (cluster + user + namespace)
  2. <context>context name from kubectl config get-contexts

My note Check twice before prod. kubectl config current-context.

Also known as: kubectx · change cluster · kubeconfig

Tool page →

Kubernetes: Set default namespace for current context

Safe

Stop typing -n on every command.

kubectl config set-context --current --namespace=<namespace>
What each part does
  1. kubectl config set-contextchange a context in your kubeconfig
  2. --currentthe context you're using now
  3. --namespace=<namespace>default namespace, so you can drop -n

Also known as: kubens · default namespace

Tool page →

OpenShift2

OpenShift: Log in with a token

Safe

Authenticate oc using the token from 'Copy login command' in the web console.

oc login --token=<token> --server=<api-url>
What each part does
  1. oc loginlog in to an OpenShift cluster
  2. --token=<token>API token (web console: your name > Copy login command)
  3. --server=<api-url>API server URL, e.g. https://api.cluster.example.com:6443

Also known as: oc login · Unauthorized · ocp login

Tool page →

OpenShift: Switch project

Safe

Change the default project (namespace). Run oc projects to list them.

oc project <project>
What each part does
  1. oc projectswitch the current project (namespace); with no argument, show the current one
  2. <project>project name

Also known as: oc project · namespace

Tool page →

AWS5

AWS: Check which identity you are using

Safe

Account, ARN and user/role the CLI is authenticated as.

aws sts get-caller-identity
What each part does
  1. aws stsSecurity Token Service commands
  2. get-caller-identityprint the account ID, user/role ARN and user ID of the current credentials; needs no permissions

Also known as: whoami aws · AccessDenied · ExpiredToken

Tool page →

AWS: Log in with an SSO profile

Safe

Opens the browser for IAM Identity Center login and caches the token.

aws sso login --profile <profile>
What each part does
  1. aws sso loginopen the browser to sign in via IAM Identity Center and cache a token
  2. --profile <profile>the profile in ~/.aws/config that holds sso_start_url / sso_session

Also known as: aws sso · The SSO session associated with this profile has expired

Tool page →

AWS: Update kubeconfig for an EKS cluster

Safe

Adds/refreshes the EKS cluster context in ~/.kube/config.

aws eks update-kubeconfig --name <cluster> --region <region> --alias <alias>
What each part does
  1. aws eks update-kubeconfigadd or update the cluster entry in ~/.kube/config and make it current
  2. --name <cluster>the EKS cluster name
  3. --region <region>region the cluster runs in
  4. --alias <alias>short context name instead of the long cluster ARN

Also known as: eks kubeconfig · You must be logged in to the server (Unauthorized)

Tool page →

AWS: Start an SSM session on an instance

Safe

Shell on an EC2 instance without SSH keys or open port 22.

aws ssm start-session --target <instance-id>
What each part does
  1. aws ssm start-sessionopen a shell on an instance through Systems Manager (no SSH, no open port)
  2. --target <instance-id>the instance, e.g. i-0abc123; needs the SSM agent + Session Manager plugin

Also known as: session manager · ssm shell · ssh alternative

Tool page →

AWS: Read a Secrets Manager secret

Caution

Prints the secret value. Mind your terminal history and screen sharing.

aws secretsmanager get-secret-value --secret-id <secret-name> --query SecretString --output text
What each part does
  1. aws secretsmanager get-secret-valuefetch the current version of a secret
  2. --secret-id <secret-name>secret name or full ARN
  3. --query SecretStringJMESPath: keep only the secret payload, drop the metadata
  4. --output textprint it raw, without JSON quotes

Also known as: secrets manager · get secret

Tool page →

Azure3

Azure: Log in and select a subscription

Safe

Interactive login, then pin the subscription for following commands.

az login && az account set --subscription "<subscription>"
What each part does
  1. az loginsign in via the browser (or device code)
  2. &&run the next command only if login succeeded
  3. az account setchange the active subscription for later az commands
  4. --subscription "<subscription>"subscription name or ID

Also known as: az login · azure subscription

Tool page →

Azure: Get AKS cluster credentials

Safe

Merge the AKS cluster into ~/.kube/config.

az aks get-credentials -g <resource-group> -n <cluster>
What each part does
  1. az aks get-credentialsmerge the AKS cluster into ~/.kube/config and switch to it
  2. -g <resource-group>resource group that holds the cluster
  3. -n <cluster>the cluster name

Also known as: aks kubeconfig · az aks

Tool page →

Azure: Read a Key Vault secret

Caution

Prints a secret's current value.

az keyvault secret show --vault-name <vault> -n <secret-name> --query value -o tsv
What each part does
  1. az keyvault secret showread the current version of a Key Vault secret
  2. --vault-name <vault>the Key Vault name
  3. -n <secret-name>the secret name
  4. --query valueJMESPath: keep only the secret value
  5. -o tsvplain text output without JSON quotes

Also known as: key vault · keyvault

Tool page →

GCP2

GCP: Log in and set the project

Safe

Authenticate the CLI and set the default project.

gcloud auth login && gcloud config set project <project-id>
What each part does
  1. gcloud auth loginsign in via the browser
  2. &&continue only if login succeeded
  3. gcloud config set project <project-id>default project for later gcloud commands

Also known as: gcloud login · gcloud project

Tool page →

GCP: Get GKE cluster credentials

Safe

Adds the GKE cluster context to ~/.kube/config.

gcloud container clusters get-credentials <cluster> --region <region>
What each part does
  1. gcloud container clusters get-credentials <cluster>write the GKE cluster into ~/.kube/config and switch to it
  2. --region <region>for regional clusters; use --zone for zonal ones

Also known as: gke kubeconfig

Tool page →

Ansible2

Ansible: Ping all hosts in an inventory

Safe

Checks SSH connectivity and Python on every host (not ICMP ping).

ansible all -i <inventory> -m ping
What each part does
  1. ansiblerun a single ad-hoc module (no playbook)
  2. allhost pattern: every host in the inventory
  3. -i <inventory>inventory file or directory
  4. -m pingthe ping module: checks SSH login + Python on the host (not ICMP); success prints pong

Also known as: UNREACHABLE · ansible ping

Tool page →

Ansible: Edit an encrypted vault file

Safe

Decrypts into $EDITOR and re-encrypts on save.

ansible-vault edit <file>
What each part does
  1. ansible-vault editdecrypt to a temp file, open it in $EDITOR, re-encrypt on save
  2. <file>the vault-encrypted file; asks for the vault password (or use --vault-password-file)

Also known as: ansible vault · vault password

Tool page →

Grafana1

Grafana: Reset the admin password

Caution

Run on the Grafana host/container when the admin login is lost.

grafana cli admin reset-admin-password <new-password>
What each part does
  1. grafana cliGrafana's command line (grafana-cli on older versions); run on the server
  2. admin reset-admin-passwordset a new password for the admin user directly in the database
  3. <new-password>the new password

Also known as: forgot admin password · grafana-cli

Tool page →

Vault2

Vault: Log in with OIDC

Safe

Browser-based SSO login; stores a token in ~/.vault-token.

vault login -method=oidc role=<role>
What each part does
  1. vault loginauthenticate and store a token in ~/.vault-token
  2. -method=oidcsign in through the browser with your SSO provider
  3. role=<role>the OIDC role configured in Vault (decides your policies)

Also known as: vault login · permission denied vault

Tool page →

Vault: Read a KV secret

Caution

Read the latest version of a KV v2 secret. Add -field=<key> for a single value.

vault kv get -mount=<mount> <path>
What each part does
  1. vault kv getread a secret from a KV engine (v1 or v2)
  2. -mount=<mount>where the engine is mounted, e.g. secret
  3. <path>path inside the mount, e.g. myapp/db; add -field=password for one value

Also known as: vault kv · read secret

Tool page →

Consul1

Consul: Read a KV value

Safe

Read one key; add -recurse to dump a prefix.

consul kv get <key>
What each part does
  1. consul kv getread a value from Consul's key/value store
  2. <key>key path, e.g. config/app/db_url; add -recurse to read a whole prefix

Also known as: consul kv

Tool page →

My DevOps Playbook by Angelo John Calleja

New runbook

GitHub not connected

Saving is handled by the site: the GitHub token is stored in Cloudflare, not in your browser. Enter the editor password (the EDITOR_PASSWORD secret) to unlock saving in this browser.

Saving commits to gelogrammer/My_DevOps_Playbook. Create a fine-grained token with access to only this repo andContents: Read and write, then paste it here. It is stored only in this browser.

src/content/docs/…