Claude Code Security on Cloud Computers
In this article
Yes, you can use Claude Code securely on a cloud computer by isolating your environment, encrypting data, and limiting access—but only if you follow strict security practices from setup to shutdown. This protects your code, credentials, and system from exposure or compromise.
What You'll Need
- A trusted cloud computing provider (such as AWS, Google Cloud, or Azure)
- SSH key pair for secure login
- Virtual private cloud (VPC) or private subnet configuration
- Firewall or security group rules
- Code editor or IDE accessible over secure connection
- Version control system (e.g., Git) with private repository
- Two-factor authentication (2FA) enabled on all accounts
Step-by-Step
- Choose a cloud provider known for strong security compliance (e.g., AWS, GCP, Azure). Avoid lesser-known or free-tier-only platforms that may lack audit logs or encryption by default.
- Create a new virtual machine (VM) instance in a private subnet within a virtual private cloud (VPC). Ensure the VM does not have a public IP unless absolutely required—and if so, assign it temporarily.
- Set up firewall rules (security groups or firewall policies) to allow only your IP address to access SSH (port 22) or HTTPS (port 443). Block all other inbound traffic by default.
- Generate an SSH key pair locally on your device. Never generate keys on the cloud instance. Upload only the public key to the cloud VM during setup or via authorized_keys.
- Connect to the VM using SSH with your private key. Use a command like
ssh -i ~/.ssh/your-key user@instance-ip. Never use password-based login. - Once connected, disable password authentication and root login in the SSH daemon configuration. Edit
/etc/ssh/sshd_configand setPasswordAuthentication noandPermitRootLogin no, then restart SSH withsudo systemctl restart sshd. - Install only the tools you need—such as a minimal code editor (e.g., VS Code Server or Vim) and Git. Avoid unnecessary software that increases attack surface.
- Clone your code repository using SSH, not HTTPS, to avoid storing tokens in plaintext. Ensure the remote is a private repo with access restricted to authorized users.
- If using a web-based IDE (like Gitpod or GitHub Codespaces), ensure it runs inside your private VPC or uses end-to-end encryption and short-lived access tokens.
- Encrypt sensitive files (e.g., config files, credentials) using tools like
gpgoragebefore storing or transferring. Never leave secrets in environment variables visible to logs. - Enable logging and monitoring for SSH access and file changes. Use built-in cloud logging (e.g., CloudWatch, Cloud Logging) to detect unauthorized access attempts.
- Set up automatic shutdown or deletion policies for the instance after a time limit (e.g., 24 hours) to reduce exposure window.
- When done, terminate the instance and securely wipe any attached storage. Use cloud provider tools to delete disks permanently, not just detach.
Common Mistakes
Leaving SSH open to the world (0.0.0.0/0) invites brute-force attacks. Using default passwords or weak keys compromises authentication. Storing API keys or credentials in plain text within the code or environment is a top cause of breaches. Forgetting to disable root login allows attackers full control if they gain access. Not encrypting data at rest leaves files vulnerable if storage is compromised. Reusing the same instance across projects increases the risk of cross-contamination.
Tips
Use ephemeral instances: spin up a new VM for each coding session and destroy it afterward. Automate setup with infrastructure-as-code (e.g., Terraform) to ensure consistent, secure configurations. Use temporary SSH certificates instead of long-lived keys when possible. Route all traffic through a bastion host or jump server instead of direct access. Keep your local machine secure—since private keys reside there, malware could steal them.
Troubleshooting
If you can’t connect via SSH, first verify the instance is running and has a public IP (if required). Check that your IP hasn’t changed—dynamic IPs can break firewall rules. Confirm the security group allows inbound traffic on port 22 from your current location. Ensure your private key has correct permissions: run chmod 600 ~/.ssh/your-key. If SSH fails after disabling password login, you may need to use the cloud provider’s serial console to regain access. If files are missing, confirm the instance didn’t auto-terminate or the disk wasn’t deleted. Always back up important code before shutting down.
Frequently Asked Questions
Can I use Claude Code on any cloud provider?
Yes, but only if you control the security setup. Avoid shared or public workspaces unless fully encrypted and access-controlled.
Should I use a public or private IP for my cloud instance?
Use a private IP and connect through a bastion host or VPN. Public IPs increase exposure unless tightly restricted by firewall rules.
How do I protect API keys when coding in the cloud?
Never hardcode them. Use encrypted files or cloud secret managers (e.g., AWS Secrets Manager) with short-lived access tokens.
Is it safe to run code from untrusted sources in the cloud?
No. Even in isolated environments, vulnerabilities can allow escape to host systems or network lateral movement.
Can I recover lost code if the instance is deleted?
Only if you pushed to a remote Git repo or backed up externally. Cloud instances do not auto-save code to persistent storage.
Do I need a firewall if I use SSH keys?
Yes. SSH keys prevent password guessing, but firewall rules block unauthorized access attempts entirely, reducing logs and risk.