Linux CLI Best Practices
Shared portable guidance for Go engineers operating services on Linux hosts, in CI, and inside containers.
Search across all documentation pages
Shared portable guidance for Go engineers operating services on Linux hosts, in CI, and inside containers.
Apply these rules in runbooks, onboarding checklists, and code review when shell workflows touch production paths.
go.mod visible. Wrong working directories produce confusing go test and relative config errors.GOPATH/bin and GOROOT/bin on PATH in login and non-login shells. CI and cron jobs miss go install tools otherwise.GOTOOLCHAIN policy explicitly (auto vs local). Reproducible releases should not surprise-download mid-pipeline.GOPRIVATE with direnv, not global .bashrc. Prevents leaking org module settings into personal repos.GOOS, GOARCH, CGO_ENABLED). Ship the ELF binary your server actually runs.SIGTERM and graceful shutdown before kill -9. Validates Go Shutdown paths you rely on in systemd and Kubernetes.pgrep/ss before restarting services. Avoid killing the wrong binary on shared hosts.LimitNOFILE (or ulimits) for high-connection Go servers. Default 1024 exhausts under moderate HTTP concurrency.TimeoutStopSec with in-process shutdown timeouts. Prevents SIGKILL mid-request drain.go test ./... evidence gathering.jq filters. trace_id, level, and msg should not rename per release without notice.grep -R. Respect .gitignore to skip vendor/ and build artifacts.tee during incidents. Pipes alone lose evidence when scrollback truncates.journalctl --since windows. Kernel OOM and unit restart lines explain silent Go process exits.go test ./... -count=1 before pushing when CI does the same. Cache hides flakes locally.-race in CI for pure Go packages unless documented otherwise. Data races are cheaper to fix pre-prod.artifacts/ with timestamps. Supports postmortems and perf comparisons (pprof -base).:6060 on 0.0.0.0 is a known exposure.EnvironmentFile or secret agents.Restart=on-failure with RestartSec backoff. Crash loops should not hammer databases on startup./opt/<app>/bin with atomic symlink swaps. Supports rollback without editing unit files.ExecStart manually as the service user before enable. Catches permission and path errors early..dockerignore excluding .git, tests, and local artifacts. Image size and cache churn stay predictable.kubectl describe Events for probe and exit codes. Logs alone miss CrashLoopBackOff root causes.kubectl logs --previous after crashes. Current container logs may be empty on instant failure.kubectl port-forward after debugging. Tunnels bypass policy you assume protects admin ports..envrc diffs. Prevents malicious env injection on shared clones.kubectl, docker, jq). CLI flag differences break copy-paste during incidents.Anyone shipping to Linux VMs should read unit files and journalctl.
Kubernetes-only teams still benefit from signal and logging concepts systemd illustrates.
Most apply conceptually.
Replace journalctl with local log files and validate Linux-specific paths before production SSH.
Capture logs and command output with timestamps before restarting pods or services.
Restarts destroy the first minute of evidence.
Yes for debug jobs and log artifact analysis.
Runtime images can stay minimal if debug tools run only in CI workers.
Operational habits (stdout vs stderr, exit codes) mirror the CLI Tools section.
Align operator scripts with how your Go binaries behave.
When graceful shutdown hangs past policy timeout and traffic is already drained elsewhere.
Document the exception in runbooks.
Local and staging debugging still benefits.
CI does not replace interactive exploration on bastion hosts.
Review quarterly or when Go minor version, base image, or orchestrator policy changes.
Read-only RBAC plus documented commands reduces risk.
Pair access with this checklist in onboarding.
WSL2 covers most Linux CLI practice.
Production alignment still requires testing on Linux CI images.
Yes.
Lint CI for tee artifacts, direnv in devcontainer, systemd unit validation with systemd-analyze verify.
Prioritize sections C, D, and F.
systemd rules matter when you still SSH to nodes or use VM-based build agents.
Stack versions: This page was written for Go 1.26.x (Green Tea GC default, go fix modernizers - verify patch at build), chi (latest - verify at build), gin (latest - verify at build), echo (latest - verify at build), google.golang.org/grpc (latest - verify at build), sigs.k8s.io/controller-runtime (latest - verify at build), kubebuilder (latest - verify at build), tinygo (latest - verify board targets at build), wazero (latest - verify at build), and golangci-lint (latest - verify linter set at build).
Reviewed by Chris St. John·Last updated Jul 18, 2026