How do I disconnect from my EC2 Instance?
Master System Design with Codemia
Enhance your system design skills with over 120 practice problems, detailed solutions, and hands-on exercises.
Introduction
"Disconnecting" from an EC2 instance can mean three different things: closing your remote session, stopping the instance, or terminating it permanently. Those actions are very different in AWS. Most of the time, if you simply want to leave the server, you only need to end the SSH or remote-console session and leave the instance running.
Close the Remote Session Without Affecting the Instance
If you connected over SSH from a terminal, disconnecting is just ending that shell session.
You can also press Ctrl+D in most shells.
That closes your client connection but keeps the EC2 instance running. Any background processes that were already detached or managed by a service manager such as systemd continue running.
If you used EC2 Instance Connect in the browser, simply closing the browser tab ends the interactive session but does not stop the instance.
Stop the Instance If You Want It Powered Off
Stopping an instance is different from disconnecting. A stopped instance is powered off, but its EBS-backed root volume remains and the instance can usually be started again later.
You can stop it from the AWS CLI:
Or from the AWS console:
- go to EC2
- select the instance
- choose
Instance state - choose
Stop instance
This is useful when you want to pause usage and reduce compute charges without deleting the machine entirely.
Terminate the Instance Only If You Are Done With It
Terminating an instance is a destructive action. Once terminated, the instance itself is gone and cannot be restarted.
Use termination only when you are certain you no longer need the instance. Depending on your storage settings, attached volumes may also be deleted automatically.
This is not a "disconnect" action. It is resource destruction.
What Happens to Your Work When You Disconnect
Closing SSH does not automatically stop commands running in the foreground unless they are tied to that terminal session. For long-running jobs, use tools such as tmux, screen, nohup, or a service manager.
Then detach from tmux and exit SSH safely. That way your work continues even after you disconnect.
If you run a foreground process directly in a plain shell and then disconnect, it may receive a hangup signal and stop.
Elastic IP and Billing Clarifications
Disconnecting from the instance does not release an Elastic IP, stop storage billing, or change security groups.
Stopping the instance may stop compute billing, but storage charges such as EBS volumes can continue. Terminating the instance may delete some storage depending on volume settings.
This matters because many beginners use "disconnect" when they actually mean "stop paying for the instance." The correct action for that is usually Stop instance, not just exiting SSH.
Common Pitfalls
The most common mistake is confusing exit from an SSH shell with stopping the instance. Exiting the shell only closes your session.
Another issue is terminating an instance when the intended action was only to disconnect or stop it temporarily.
Developers also often forget that long-running commands tied to the shell may die when the session ends. Use tmux, screen, nohup, or a proper service.
Finally, do not assume disconnecting changes billing. Billing depends on the instance state and attached resources, not on whether your terminal is open.
Summary
- Use
exitorCtrl+Dto disconnect from an SSH session while leaving the instance running. - Stop the instance if you want it powered off but still reusable later.
- Terminate the instance only if you want to delete it permanently.
- Use
tmux,screen, or service management for long-running work. - Keep "disconnect," "stop," and "terminate" separate in your AWS workflow.

