Configure environment variables in Linux, macOS, and Windows
Set an Alibaba Cloud AccessKey pair as environment variables on Linux, macOS, and Windows so your applications can authenticate securely without hardcoded credentials.
An Alibaba Cloud account has full resource access and poses high security risks. We recommend using a RAM user with only the required permissions. To obtain a RAM user's AccessKey pair, see Create an AccessKey and Manage permissions for a RAM user. Never hardcode plaintext AccessKeys in your code — use environment variables or other secure methods instead.
Linux and macOS
The following examples use ALIBABA_CLOUD_ACCESS_KEY_ID and ALIBABA_CLOUD_ACCESS_KEY_SECRET as variable names. Replace them with your own names if needed, such as OSS_ACCESS_KEY_ID and OSS_ACCESS_KEY_SECRET.
Run the following export commands to set environment variables:
Variables set with export are temporary and valid only for the current session. For persistence, add the export command to your shell startup file (such as ~/.bashrc or ~/.zshrc).
-
Set the AccessKey ID:
# Replace yourAccessKeyID with your AccessKey ID. export ALIBABA_CLOUD_ACCESS_KEY_ID=yourAccessKeyID -
Set the AccessKey Secret:
# Replace yourAccessKeySecret with your AccessKey secret. export ALIBABA_CLOUD_ACCESS_KEY_SECRET=yourAccessKeySecret -
Verify the configuration.
Run
echo $ALIBABA_CLOUD_ACCESS_KEY_ID. If the correct value is returned, the configuration is successful.
Windows
The following examples use ALIBABA_CLOUD_ACCESS_KEY_ID and ALIBABA_CLOUD_ACCESS_KEY_SECRET as variable names. Replace them with your own names if needed, such as OSS_ACCESS_KEY_ID and OSS_ACCESS_KEY_SECRET.
Use GUI
-
Procedure
To configure environment variables through the Windows 10 GUI:
Right-click This PC on the desktop and select Properties. Click Advanced system settings. On the Advanced tab, click Environment Variables. Click New in the User variables or System variables section and add the following variables.
Variable
Example
AccessKey ID
-
Variable name: ALIBABA_CLOUD_ACCESS_KEY_ID
-
Variable value: LTAI****************
AccessKey Secret
-
Variable name: ALIBABA_CLOUD_ACCESS_KEY_SECRET
-
Variable value: yourAccessKeySecret
-
-
Verify the configuration.
Press Win+R , enter cmd , and press Enter. Run
echo %ALIBABA_CLOUD_ACCESS_KEY_ID%andecho %ALIBABA_CLOUD_ACCESS_KEY_SECRET%. If the correct values are returned, the configuration is successful.
Use CMD
-
Procedure
Open Command Prompt as an administrator and run the following commands:
setx ALIBABA_CLOUD_ACCESS_KEY_ID yourAccessKeyID /M setx ALIBABA_CLOUD_ACCESS_KEY_SECRET XXXXXXX /MThe
/Mparameter sets a system variable. Omit it to set a user variable instead. -
Verify the configuration.
Press Win+R , enter cmd , and press Enter. Run
echo %ALIBABA_CLOUD_ACCESS_KEY_ID%andecho %ALIBABA_CLOUD_ACCESS_KEY_SECRET%. If the correct values are returned, the configuration is successful.
Use Windows PowerShell
Set persistent environment variables for the current user. These take effect in all new sessions.
[System.Environment]::SetEnvironmentVariable('ALIBABA_CLOUD_ACCESS_KEY_ID', 'yourAccessKeyID', [System.EnvironmentVariableTarget]::User)
[System.Environment]::SetEnvironmentVariable('ALIBABA_CLOUD_ACCESS_KEY_SECRET', 'XXXXXXX', [System.EnvironmentVariableTarget]::User)
Set environment variables for all users (requires administrator privileges):
[System.Environment]::SetEnvironmentVariable('ALIBABA_CLOUD_ACCESS_KEY_ID', 'yourAccessKeyID', [System.EnvironmentVariableTarget]::Machine)
[System.Environment]::SetEnvironmentVariable('ALIBABA_CLOUD_ACCESS_KEY_SECRET', 'XXXXXXX', [System.EnvironmentVariableTarget]::Machine)
Set variables for the current session only:
$env:ALIBABA_CLOUD_ACCESS_KEY_ID = "yourAccessKeyID"
$env:ALIBABA_CLOUD_ACCESS_KEY_SECRET = "XXXXXXX"
Run Get-ChildItem env:ALIBABA_CLOUD_ACCESS_KEY_ID and Get-ChildItem env:ALIBABA_CLOUD_ACCESS_KEY_SECRET. If the correct values are returned, the configuration is successful.
After configuring environment variables, restart your IDE or related services for the changes to take effect.