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:
However if I use the session manager, the configuration files are not sourced as you can see here:
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With