Skip to content

How can I change the Session Manager shell to bash on EC2 Linux instances?

3 minute read
0

I want to change the Session Manager, a capability of AWS Systems Manager, default shell on my Amazon Elastic Compute Cloud (Amazon EC2) Linux instance.

Short description

Session Manager sessions on Amazon EC2 Linux instances use the Bourne shell (sh) by default. However, bash is the default shell in major Linux distributions. To use bash instead of sh, you can use configurable shell profiles to change the default Session Manager shell from sh to bash. Shell profiles allow you to customize the following preferences within sessions when you use Session Manager:

  • Shell preferences
  • Environment variables
  • Working directories
  • Running multiple commands when a session starts

You can use the Systems Manager console or the AWS Command Line Interface (AWS CLI) to turn on configurable shell profiles.

Resolution

Note: If you receive errors when you run AWS CLI commands, then see Troubleshoot AWS CLI errors. Also, make sure that you're using the most recent AWS CLI version.

Prerequisite:

To turn on shell profiles, you must use AWS Systems Manager Agent (SSM Agent) version 3.0.196.0 or later. Check the SSM Agent version number on your instance and update the SSM Agent, if necessary. For more information, see Automating updates to SSM Agent.

To see the available shells on the instance, run the following command:

$ sudo cat /etc/shells

Note: You can use any of the shells that are returned from the preceding command.

Use the console to turn on configurable shell profiles

To use the Systems Manager console to turn on configurable shell profiles and change the shell to bash, complete the following steps:

  1. Open the Systems Manager console.

  2. From the navigation pane, choose Session Manager.

  3. Choose the Preferences tab, and then choose Edit.

  4. For linux under shellProfile, enter the following information:

    /bin/bash
  5. Choose Save.

Use the AWS CLI to turn on configurable shell profiles

To use the AWS CLI to turn on configurable shell profiles and change the shell to bash, complete the instructions on Create a Session Manager preferences document (command line).

Use other shell profile configuration options

You can use the shell profile to load specific environment variables, or to run a script at the start of the session. For example, to add the PYTHONPATH environment variable, add the following command to your shell profile:

export PYTHONPATH=/usr/lib/python2.7

When you are logged in, run the following command to verify that the environment variable is correctly set:

$ sudo env

Related information

Allow configurable shell profiles

Grant or deny a user permissions to update Session Manager preferences

Specify an idle session timeout value

AWS OFFICIALUpdated a year ago