Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

AWS Session Manager is not sourcing bash rc

I am using AWS Systems Manager Session Manager to connect to my EC2 instance.

When I connect, the session does not source my .bashrc or .bash_profile, so I get a pretty plain shell and would like to setup some configuration when it starts.

The session manager connects me as the ec2-user but the shell starts in the / directory and not the user directory.

I am unable to figure out if it is sourcing any configuration files when it starts up.
How can I get it to source the users configuration files?

I have set up session manager to use the ec2-user by enabling the "run as support" setting.

If I connect to an instance using the EC2 instance connect then it works as you can see here: EC2 instance connect with sourced files

However if I use the session manager, the configuration files are not sourced as you can see here:

enter image description here

like image 588
morras Avatar asked Oct 20 '25 10:10

morras


1 Answers

AWS Systems Manager Session Manager uses an "agent" to establish a connection with the Amazon EC2 instance. The agent registers the instance with Systems Manager. When a connection is requested, a message is sent to the agent. Commands are then sent to the agent, which executes them locally and sends back the results.

Therefore, Session Manager is not actually logged into a bash session. It is simply executing the commands one-at-a-time as received.

The benefit of Session Manager is that it can be used to connect to a private EC2 instance because the agent establishes an 'outbound' connection to AWS, rather than the connection request being sent 'to' the instance.

Amazon EC2 Instance Connect, in contrast, actually establishes a normal SSH connection to the instance. The web browser uses a Guacamole connection to AWS, which then uses normal SSH (with an extra hack to permit temporary keypairs) to run the commands. Therefore, it looks like a normal connection running against the shell.

You can actually use the "temporary SSH keys" feature of EC2 Instance Connect together with a normal SSH client, without using the web-based SSH client. Thus, it's actually two features in one: a web-based SSH client, and a means of using temporary keypairs to establish the SSH connection.

like image 200
John Rotenstein Avatar answered Oct 22 '25 23:10

John Rotenstein