# Advanced options for EC2 instances

For optimal use of the EC2 Mac and Linux instances, we recommend additional configuration that is not strictly required for the instances to run Bitrise builds. Some of these configuration options are best set during instance creation.

## Connectivity and security of your EC2 Mac and Linux instance

Once your EC2 Mac or Linux instance is ready, make sure you can connect to the instance and that it can connect to the relevant Bitrise services. You can connect to the instance using SSH or in the case of EC2 Mac instances, VNC.

You can also set a password for your instance.

### Instance passwords

:::note[User data]

To make sure instance behavior is consistent across all instances, we recommend configuring this as part of [user data](https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/user-data.html#user-data-console) during [instance creation](/bitrise-platform/infrastructure/bitrise-on-aws--manual-setup/launching-an-ec2-instance-for-the-bitrise-ami).

User data is provided either in plain text or in base64 encoded format.

:::

By default, the Bitrise AMI doesn't have user passwords. It is the subscriber's responsibility to set the desired password.

For an EC2 Mac instance, you need to set a user password and the default `login.keychain` password:

```bash
sudo /usr/bin/dscl . -passwd /Users/ec2-user
security set-keychain-password  -o "" -p "<new password>" ~/Library/Keychains/login.keychain-db
```

For a Linux instance:

```bash
sudo passwd
```

### Connecting to the instance

To connect to your instance using SSH, we recommend using TCP port 22. To connect to the instance via SSH:

  

**macOS**

  - ```bash
    ssh -i "&lt;your-ssh-key&gt;" ec2-user@&lt;your-mac2-instance&gt;
    ```

    You can also connect with VNC. We recommend using TCP port 5900. To connect:

    ```bash
    open vnc://ec2-user@&lt;aws-mac2-instance&gt;
    ```

  
  

**Linux**

  - ```bash
    ssh -i ~/.ssh/key   ubuntu@<your-aws-instance>
    ```

  </TabItem>
</Tabs>

:::important[Security group configuration]

Make sure to enable the use of both ports in your [security group configuration](https://docs.aws.amazon.com/cli/latest/userguide/cli-services-ec2-sg.html) of the instance!

:::

## Pre-warming the disk after booting

:::note[User data]

To make sure instance behavior is consistent across all instances, we recommend configuring this as part of [user data](https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/user-data.html#user-data-console) during [instance creation](/bitrise-platform/infrastructure/bitrise-on-aws--manual-setup/launching-an-ec2-instance-for-the-bitrise-ami).

User data is provided either in plain text or in base64 encoded format.

:::

You can improve Amazon EBS performance by pre-warming the disk right after booting it up. You only need to do it once.

:::important[Recommended for virtualization]

We highly recommend pre-warming the disk if you use our virtualized offering.

:::

<Tabs>
  <TabItem value="mac" label="Mac instance">

  - ```bash
    export cnt=$(($(df -h | grep "/$" | awk '{print $4}' | grep -oE "[0-9]+")-2))
    sudo dd if=/dev/random of=bigfile bs=1g count=$cnt
    ```

  
  

**Linux instance**

  - ```bash
    sudo dd if=/dev/xvdf of=/dev/null bs=1M
    ```

    :::note[dev/xvfd]

    Be aware that `xvdf` might be different on your machine

    :::

  </TabItem>
</Tabs>

## Increasing disk size on an EC2 Mac instance

:::note[User data]

To make sure instance behavior is consistent across all instances, we recommend configuring this as part of [user data](https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/user-data.html#user-data-console) during [instance creation](/bitrise-platform/infrastructure/bitrise-on-aws--manual-setup/launching-an-ec2-instance-for-the-bitrise-ami).

User data is provided either in plain text or in base64 encoded format.

:::

If you have configured a bigger Amazon EBS storage for your EC2 Mac instance than the default (400 GB), resize the partition so macOS can use all available disk space:

```bash
PDISK=$(diskutil list physical external | head -n1 | cut -d" " -f1)
APFSCONT=$(diskutil list physical external | grep "Apple_APFS" | tr -s " " | cut -d" " -f8)
yes | sudo diskutil repairDisk $PDISK

sudo diskutil apfs resizeContainer $APFSCONT 0
```

For more information, please refer to the [AWS macOS EC2 documentation](https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/ec2-mac-instances.html#mac-instance-increase-volume).

## Cleaning up your AWS build environment

When running a self-hosted agent, one agent executes multiple builds (one after the other). This allows sharing of data between builds on the local filesystem, but it also requires some care in order to avoid one build affecting another.

To avoid this problem, you can clean up your build environment in between builds. To do so, you need to run the [Bitrise CLI](/bitrise-ci/bitrise-cli/installing-and-updating-the-bitrise-cli) on the self-hosted machines in agent mode: [Cleaning up persistent build environments](/bitrise-platform/infrastructure/cleaning-up-persistent-build-environments)

## Using secrets in your builds running on AWS

You can use secret Environment Variables even if your organization's security policy doesn't allow you to host them on bitrise.io: [Secrets in self-hosted environments](/bitrise-ci/configure-builds/secrets#secrets-in-self-hosted-environments).
