Systems Manager Session Manager: servers with no open ports

In Lessons 11 and 12 you opened SSH and RDP to your own IP. It works, but now you have keys, passwords and open ports to look after. AWS Session Manager, which is part of Systems Manager, gives you a shell on Linux and Windows servers without any inbound port, public IP or SSH key, and IAM checks and logs every session.

You’ll launch app01 in a private subnet that has no internet at all, reach it through VPC endpoints, and fix the two errors that block most people’s first session. For the rest of the course, this is how we’ll get onto our servers.

TimeYou needBy the end you can
60 minutes (endpoints and instance running for under an hour)saat-vpc with saat-app-sg, your laptop signed in with aws login --profile saat-admin. Cost: about USD 0.08 if you clean up within an hour.You’ll create an instance role for Systems Manager, add the VPC endpoints a private server needs, install the Session Manager plugin, open sessions from the CLI, and sort out “TargetNotConnected” and “plugin not found”.

What it is, in one line

AWS Session Manager gives you a shell on your servers through the SSM Agent, so you never have to open an SSH or RDP port.

In Simple Words

A phone line that only rings outwards

Picture a secure office that has no front door, so nobody can walk in. Inside sits a helper who keeps a phone line open to head office. When you need something done in there, you ring head office, they check your ID badge and pass your words down the line the helper already opened, and the helper does the job and tells you how it went. Every call is recorded. In AWS terms the helper is the SSM Agent, head office is Systems Manager and your badge is IAM, and at no point did anyone open a door.

Engineer's View

What has to be in place

The SSM Agent comes pre-installed on Amazon Linux and on Amazon’s Windows AMIs. It makes outbound HTTPS connections to Systems Manager and nothing ever connects in to it. To talk to Systems Manager it needs credentials, and these usually come from an instance profile holding a role with the AmazonSSMManagedInstanceCore policy.

(There’s also an account-wide setting, Default Host Management Configuration, that does the same job without a role on each instance.)

The agent also needs a way out to the service. That’s either a NAT gateway or interface VPC endpoints for ssm, ssmmessages and ec2messages, with private DNS turned on and a security group that allows 443 from the instance. Endpoints are billed per hour per zone, so in this lab you’ll put them in one zone and delete them when you’re done.

On your laptop, aws ssm start-session won’t work without the separate Session Manager plugin. Linux sessions log you in as ssm-user, which has sudo rights, and Windows sessions drop you into PowerShell. Port forwarding uses the same channel, for example AWS-StartPortForwardingSession when you need RDP on 3389.

IAM decides who can start a session (ssm:StartSession, scoped by instance or by tag), and each session shows up in CloudTrail. If you want the full session output too, you can send it to S3 or CloudWatch Logs.

How it works, step by step

A session only opens when all four of these pieces are in place.

1Instance role

saat-ec2-ssm-role carries AmazonSSMManagedInstanceCore and sits inside the instance profile saat-ec2-ssm-profile. You’ll attach this same profile to every server from here on.

AWS Session Manager: how a session reaches a private server through VPC endpoints

2A path to Systems Manager

app01 can’t reach the internet, so the agent gets out through three interface endpoints in saat-private-a, protected by saat-endpoint-sg, which allows 443 from the VPC.

3The agent registers

A minute or two after boot, the agent should show as Online in describe-instance-information. If it never turns up, step 1 or step 2 is missing.

4You connect

Your laptop calls Systems Manager over HTTPS using your IAM identity, and the plugin carries your shell over the channel the agent has already opened.

Next to SSH and RDP, most of the gain is in the things you don’t have to protect any more.

AWS Session Manager compared with SSH and RDP

From this lesson onwards the course won’t open 22 or 3389 again. When a later lab needs a Windows desktop, you’ll use port forwarding through Session Manager, or Fleet Manager in the console.

✅ Checkpoint: You can name the four pieces a session needs and say why no inbound rule is required.

Hands-on lab: AWS Session Manager to a private server

Before you run any command, double-check it

Read every command twice before you press Enter. Check the target: the system or account, the IDs, the names and the sizes. These commands are for learning and were tested in our lab, not on your system. At work, run the read-only list commands first, follow your change process, make sure a backup exists, and ask a second person to check anything that changes or deletes data. You run them at your own risk.

Start as usual and load the network:

cd C:\aws-lab
aws login --profile saat-admin
$env:AWS_PROFILE = 'saat-admin'
$v = Get-Content C:\aws-lab\saat-vpc.json | ConvertFrom-Json

1Create the instance role and profile (keep these)

Paste this whole block:

@'
{ "Version": "2012-10-17", "Statement": [{ "Effect": "Allow", "Principal": { "Service": "ec2.amazonaws.com" }, "Action": "sts:AssumeRole" }] }
'@ | Set-Content ec2-trust.json
aws iam create-role --role-name saat-ec2-ssm-role --assume-role-policy-document file://ec2-trust.json --tags Key=course,Value=saatvedha-aws Key=lesson,Value=13 | Out-Null
aws iam attach-role-policy --role-name saat-ec2-ssm-role --policy-arn arn:aws:iam::aws:policy/AmazonSSMManagedInstanceCore
aws iam create-instance-profile --instance-profile-name saat-ec2-ssm-profile | Out-Null
aws iam add-role-to-instance-profile --instance-profile-name saat-ec2-ssm-profile --role-name saat-ec2-ssm-role

2Create the endpoint security group (keep it)

Paste this whole block:

$epSg = aws ec2 create-security-group --group-name saat-endpoint-sg --description "HTTPS from saat-vpc to interface endpoints" --vpc-id $v.VpcId --tag-specifications 'ResourceType=security-group,Tags=[{Key=Name,Value=saat-endpoint-sg},{Key=course,Value=saatvedha-aws},{Key=lesson,Value=13}]' --query GroupId --output text
aws ec2 authorize-security-group-ingress --group-id $epSg --protocol tcp --port 443 --cidr 10.20.0.0/16 | Out-Null
$v | Add-Member -NotePropertyName EndpointSg -NotePropertyValue $epSg -Force
$v | ConvertTo-Json | Set-Content C:\aws-lab\saat-vpc.json

3Create the three interface endpoints (the clock starts now)

Paste this whole block. The loop keeps checking until all three endpoints are available, which usually takes two or three minutes:

$eps = foreach ($svc in 'ssm','ssmmessages','ec2messages') {
  aws ec2 create-vpc-endpoint --vpc-id $v.VpcId --vpc-endpoint-type Interface --service-name "com.amazonaws.ap-south-1.$svc" --subnet-ids $v.PrivateA --security-group-ids $epSg --private-dns-enabled --tag-specifications "ResourceType=vpc-endpoint,Tags=[{Key=Name,Value=saat-$svc-endpoint},{Key=course,Value=saatvedha-aws},{Key=lesson,Value=13}]" --query VpcEndpoint.VpcEndpointId --output text
}
do { Start-Sleep 20; $states = aws ec2 describe-vpc-endpoints --vpc-endpoint-ids $eps --query "VpcEndpoints[].State" --output text } until (($states -split '\s+' | Where-Object { $_ -ne 'available' }).Count -eq 0)
$states

You should see this:

available       available       available

4Launch app01 in the private subnet, with no key and no public IP

Paste this whole block:

$ami = aws ssm get-parameter --name /aws/service/ami-amazon-linux-latest/al2023-ami-kernel-default-x86_64 --query Parameter.Value --output text
Start-Sleep 15
$id = aws ec2 run-instances --image-id $ami --instance-type t3.micro --subnet-id $v.PrivateA --security-group-ids $v.AppSg --iam-instance-profile Name=saat-ec2-ssm-profile --metadata-options HttpTokens=required --tag-specifications 'ResourceType=instance,Tags=[{Key=Name,Value=app01},{Key=course,Value=saatvedha-aws},{Key=lesson,Value=13},{Key=owner,Value=yourname.admin}]' --query "Instances[0].InstanceId" --output text
do { Start-Sleep 20; $ping = aws ssm describe-instance-information --filters "Key=InstanceIds,Values=$id" --query "InstanceInformationList[0].PingStatus" --output text } until ($ping -eq 'Online')
aws ssm describe-instance-information --filters "Key=InstanceIds,Values=$id" --query "InstanceInformationList[0].[PingStatus,PlatformName,AgentVersion]" --output text

You should see something like this:

Online  Amazon Linux    3.3.2746.0

The Start-Sleep 15 is there because IAM needs a few seconds before EC2 can see a brand-new instance profile. Launch straight after creating it and you can get “Invalid IAM Instance Profile name”.

5Install the Session Manager plugin

Run this:

winget install --id Amazon.SessionManagerPlugin -e
$env:Path += ';C:\Program Files\Amazon\SessionManagerPlugin\bin'
session-manager-plugin

The last line should print:

The Session Manager plugin was installed successfully. Use the AWS CLI to start a session.

Adding the folder to $env:Path means you don’t have to open a new window and lose the variables you’ve set.

6Open a session

Run this, then type the commands after the sh prompt:

aws ssm start-session --target $id

Type this at the sh-5.2$ prompt:

whoami
curl -m 5 https://checkip.amazonaws.com
exit

You should see something like this:

Starting session with SessionId: yourname.admin-0a1b2c3d4e5f67890
sh-5.2$ whoami
ssm-user
sh-5.2$ curl -m 5 https://checkip.amazonaws.com
curl: (28) Connection timed out after 5001 milliseconds
sh-5.2$ exit

Exiting session with sessionId: yourname.admin-0a1b2c3d4e5f67890.

You’re now in a shell on a server with no internet, no public IP and no inbound SSH rule. The session ID begins with your user name and it’s recorded in CloudTrail as StartSession.

AWS Session Manager lab: managed instance online and a session as ssm-user
app01 registered, then a session as ssm-user with no internet. Yours should look much like this.

✅ Checkpoint: app01 shows Online, the session opened as ssm-user, and curl to the internet failed, which proves the traffic went through the endpoints. Leave app01 and the endpoints running for the break lab.

Break It, Then Fix It

These are the two messages nearly everyone runs into on their first day with Session Manager.

1Break it: a server without an instance role

Launch app02 the same way but leave out the instance profile, give it three minutes, then try to connect:

$id2 = aws ec2 run-instances --image-id $ami --instance-type t3.micro --subnet-id $v.PrivateA --security-group-ids $v.AppSg --metadata-options HttpTokens=required --tag-specifications 'ResourceType=instance,Tags=[{Key=Name,Value=app02},{Key=course,Value=saatvedha-aws},{Key=lesson,Value=13}]' --query "Instances[0].InstanceId" --output text
Start-Sleep 180
aws ssm start-session --target $id2

You’ll get this error (something like this):

An error occurred (TargetNotConnected) when calling the StartSession operation: i-0e2f3a4b5c6d7e8f9 is not connected.

The agent is running, but without credentials it has never been able to check in, so Systems Manager doesn’t know it exists. “Not connected” won’t tell you which piece is missing, which is where the checklist from “How it works” comes in. Fix: attach the profile, restart the instance so the agent picks it up quickly, and wait until it shows Online:

aws ec2 associate-iam-instance-profile --instance-id $id2 --iam-instance-profile Name=saat-ec2-ssm-profile | Out-Null
aws ec2 reboot-instances --instance-ids $id2
do { Start-Sleep 20; $ping = aws ssm describe-instance-information --filters "Key=InstanceIds,Values=$id2" --query "InstanceInformationList[0].PingStatus" --output text } until ($ping -eq 'Online')
$ping

You should see this:

Online

2Break it: the plugin isn’t on the PATH

Take the plugin folder out of this window’s PATH and try again:

$env:Path = ($env:Path -split ';' | Where-Object { $_ -notmatch 'SessionManagerPlugin' }) -join ';'
aws ssm start-session --target $id

You’ll get this error:

SessionManagerPlugin is not found. Please refer to SessionManager Documentation here: http://docs.aws.amazon.com/console/systems-manager/session-manager-plugin-not-found
AWS Session Manager break lab: target not connected and plugin not found
Both errors from this break lab. The plugin message is word for word.

The CLI is fine; it can’t find the separate plugin program. You’ll see this on a new laptop, or when you’ve installed the plugin but haven’t opened a new window yet. Fix: put the folder back in PATH, or open a new PowerShell window.

$env:Path += ';C:\Program Files\Amazon\SessionManagerPlugin\bin'
aws ssm start-session --target $id

3Clean up

Paste this whole block:

aws ec2 terminate-instances --instance-ids $id $id2 | Out-Null
aws ec2 delete-vpc-endpoints --vpc-endpoint-ids $eps | Out-Null
aws ec2 wait instance-terminated --instance-ids $id $id2
.\Find-LabResources.ps1

Keep saat-ec2-ssm-role, saat-ec2-ssm-profile and saat-endpoint-sg, since they don’t cost anything. The three interface endpoints go, because they’re billed by the hour, and later labs that need private access either create them again or use a NAT gateway for a short time.

✅ Checkpoint: You fixed a server with no instance role and a missing plugin, then deleted both instances and all three endpoints.

This happened at work

The bastion key that fifteen people shared

This was at a SaaS company that reached all its private servers through one bastion host, using one SSH key shared by fifteen engineers. Over time that key had been copied to laptops, a build server and at least one contractor’s machine, and nobody could tell you how many copies were out there. Then one morning a production log folder was found deleted. The bastion’s logs only said “ec2-user” from the office IP, so that was a dead end. Rotating the key took a full day because every script and laptop had to be updated, and the team never found out who did the deletion.

After that the team got rid of the bastion and closed port 22 everywhere. Engineers now open Session Manager sessions with their own IAM identities, the sessions are logged to CloudWatch Logs and S3, and an IAM condition on tags controls who can start a session on production instances. The next audit took one afternoon where it used to take a week.

Common mistakes and troubleshooting

MistakeWhat happensWhat to do
No instance profile, or one without AmazonSSMManagedInstanceCoreTargetNotConnected; instance never appears as managedAttach the profile, then reboot or wait for the agent to retry
No path to Systems ManagerAgent can’t registerNAT gateway, or ssm + ssmmessages + ec2messages endpoints
Endpoints without private DNSAgent keeps trying the public endpoints and failsCreate interface endpoints with private DNS enabled
Endpoint security group without 443 from the instanceAgent times outAllow 443 from the VPC or the instance’s subnet
Plugin not installed or not on PATHSessionManagerPlugin is not foundInstall it; open a new window or add it to PATH
Launching right after creating an instance profileInvalid IAM Instance Profile nameGive IAM a few seconds to catch up

Interview questions

Click a question to open it. They’re worded the way an interviewer would ask them, and under each one you’ll find why they ask it and one way to answer, which you should put in your own words.

Fresher level

1. Can you explain in simple words what Session Manager is and why teams like it?

Why they ask this: They want to see whether you know how servers are reached today, because a lot of companies have shut SSH and RDP off completely.

How you might answer: It’s a Systems Manager feature that gives me a shell on Linux and Windows instances through the SSM Agent, so I don’t open any inbound ports or manage SSH keys. Access is controlled through IAM and every session can be logged.

2. You launch a new instance and want to connect with Session Manager. What does the instance need for that to work?

Why they ask this: They’re checking you know the three prerequisites, since most “it won’t connect” problems come down to one of them being missing.

How you might answer: It needs the SSM Agent running, and either an instance role with AmazonSSMManagedInstanceCore or Default Host Management Configuration turned on. And it needs a network path to Systems Manager, whether that’s the internet, a NAT gateway or VPC endpoints.

3. When you start a session on a Linux instance, which user are you logged in as?

Why they ask this: It’s a small practical detail that shows you’ve used it for real, and it comes up when people talk about file permissions or audit logs.

How you might answer: By default it’s ssm-user, which has sudo rights. If we need a particular OS user, I’d set that up with Run As.

2–5 years experience

4. An instance doesn’t show up in Fleet Manager, so you can’t connect. How do you troubleshoot it?

Why they ask this: They want to see you debug in a sensible order. Going through role, network and agent one by one is quicker than guessing.

How you might answer: I’d start with the instance role and its policy, then look at the network path: is there a route to NAT, or are the three endpoints there with private DNS and a security group allowing 443? After that I’d confirm the agent is running and check its version, and if I still had nothing I’d read /var/log/amazon/ssm/amazon-ssm-agent.log, or the Windows equivalent, through the serial console.

5. Only the ops team should be able to open sessions on production servers. How would you set that up?

Why they ask this: They want to see you apply IAM conditions to a real case, and production access is always a sensitive subject.

How you might answer: I’d write an IAM policy that allows ssm:StartSession only on instances tagged env=prod, only for the ops group and only with MFA, with an explicit deny for everyone else. On top of that, session documents can limit what people can do once they’re in.

6. You need to RDP to a Windows server in a private subnet, and opening 3389 isn’t allowed. How would you do it?

Why they ask this: They’re checking you know Session Manager port forwarding, because it solves a problem people hit almost every day.

How you might answer: I’d use Session Manager port forwarding with the AWS-StartPortForwardingSession document, mapping a local port such as 13389 to 3389 on the instance, and then point mstsc at localhost:13389. If someone prefers the console, Fleet Manager Remote Desktop works too.

Senior level

7. Walk me through how you’d design admin access for 500 servers across 20 accounts, with no inbound ports at all.

Why they ask this: They want to see you put the pieces together at scale, and they’ll be listening for logging and guardrails as well as access.

How you might answer: In every account I’d have infrastructure code set up Default Host Management Configuration or a standard instance role, plus VPC endpoints or NAT in each VPC. Session Manager preferences would send logs to a central S3 bucket and CloudWatch Logs, encrypted with KMS. IAM Identity Center permission sets would allow sessions by tag, and SCPs would deny any security group rule that opens 22 or 3389.

8. For Systems Manager traffic, would you use interface endpoints or a NAT gateway? What are the trade-offs?

Why they ask this: They want cost and security thinking in the same answer. There isn’t one right choice, so it’s your reasoning they care about.

How you might answer: Endpoints keep the traffic private without giving the server general internet access, but you pay per endpoint, per zone, per hour, and across lots of VPCs that adds up. A NAT gateway is one hourly charge per zone, though it does open general internet access. With many VPCs I’d look at shared endpoints in a central VPC with Route 53 Resolver to keep the cost down.

Quick quiz

Q1. Which inbound port must be open for Session Manager?

  1. 22
  2. 3389
  3. 443
  4. None
Show answer

D: The agent connects outwards, so the instance needs no inbound rule.

Q2. Which managed policy does the instance role need?

  1. AdministratorAccess
  2. AmazonSSMManagedInstanceCore
  3. ReadOnlyAccess
  4. AmazonEC2FullAccess
Show answer

B: AmazonSSMManagedInstanceCore is what lets the agent register and receive sessions.

Q3. Which interface endpoints does a server without internet access need for Session Manager?

  1. s3 only
  2. ssm, ssmmessages, ec2messages
  3. sts and kms
  4. ec2 and iam
Show answer

B: These three endpoints let the agent reach Systems Manager privately.

Q4. start-session fails with TargetNotConnected. What is a likely cause?

  1. Wrong Region in the browser
  2. The instance has no instance role
  3. Port 22 is closed
  4. The plugin is too new
Show answer

B: With no credentials the agent can’t register, so the target never connects.

Q5. What does “SessionManagerPlugin is not found” mean?

  1. The instance has no agent
  2. The plugin isn’t installed or isn’t on your laptop’s PATH
  3. The endpoints are missing
  4. IAM denied the session
Show answer

B: The CLI needs the separate plugin program installed on your laptop.

Quick recap

  • Session Manager gives you a shell without inbound ports, keys or a public IP.
  • The instance needs the SSM Agent, a role with AmazonSSMManagedInstanceCore and a path out (NAT or the ssm, ssmmessages and ec2messages endpoints).
  • Your laptop needs the Session Manager plugin, and every session is authorised by IAM and logged.
  • TargetNotConnected points to a missing role or network path; “plugin not found” is a problem on your laptop.
  • saat-ec2-ssm-profile and saat-endpoint-sg stay for later lessons, and the interface endpoints get deleted after each lab.

Next lesson

Lesson 14: EBS volumes: gp3, io2, snapshots and resizing → You’ll add, grow and back up disks on a running server with no downtime.

Further reading: AWS Session Manager

Want to go deeper into AWS Session Manager? Read AWS Systems Manager Session Manager and Improve the security of EC2 instances by using VPC endpoints for Systems Manager. You can also see the full plan for this course on the AWS Cloud Administration course page.

Scroll to Top

This website uses cookies

We use a few cookies to keep this site working. If you allow it, we also use Google Analytics to count visits so we can improve our lessons. You can accept all, deny the optional ones, or choose what to allow.