This topic describes how to log on to an E-MapReduce (EMR) cluster by using an SSH key pair or password. You can log on to an EMR cluster from an on-premises machine that runs a Linux or Windows operating system.
Prerequisites
- An EMR cluster is created. For more information, see Create a cluster.
- Your on-premises machine is connected to the master node of the cluster. You can turn on Assign Public IP Address during cluster creation to associate an elastic IP address (EIP) with your cluster. You can also assign a fixed public IP address or an EIP address to the master node of your cluster in the ECS console after the cluster is created. For more information, see Bind an ENI.
Background information
After your on-premises machine is connected to the master node of your cluster in SSH mode, you can run Linux commands to monitor the cluster and interact with the cluster. You can also create an SSH tunnel to view the web UIs of open source components. For more information, see Create an SSH tunnel to access web UIs of open source components.
Obtain the public IP address of the master node
Log on to the cluster by using an SSH key pair
- Log on from your on-premises machine that runs a Linux operating system
In this example, the private key file ecs.pem is used.
- Run the following command to modify the attribute of the private key file:
chmod 400 ~/.ssh/ecs.pem
~/.ssh/ecs.pem
is the path where the ecs.pem file is stored on your on-premises machine. - Run the following command to connect to the master node:
ssh -i ~/.ssh/ecs.pem root@<Public IP address of the master node>
- Run the following command to modify the attribute of the private key file:
- Use PuTTY to log on from your on-premises machine that runs a Windows operating system
Perform the following steps to log on to the cluster:
- Download PuTTY and PuTTYgen.
- Convert the format of the private key file from .pem to .ppk.
- Run PuTTYgen. In this example, PuTTYgen 0.73 is used.
- In the Actions section, click Load to import the private key file that is saved when you create a cluster.
Make sure that the format of the file that you want to import is All files (*.*).
- Select the specific .pem file and click Open.
- Click Save private key.
- In the dialog box that appears, click Yes. Specify a name for the .ppk file and click Save.
Save the .ppk file to your on-premises machine. In this example, kp-123.ppk is used.
- Run PuTTY.
- In the left-side navigation pane, choose Browse below Private key file for authentication and select the .ppk file. . Click
- Click Session. Enter the logon account and the public IP address of the master node in the Host Name (or IP address) field.
The format is root@[Public IP address of the master node], such as root@10.10.xx.xx.
- Click Open.
If the following information appears, the logon is successful.
- Use Command Prompt to log on from your on-premises machine that runs a Windows operating
system
Open Command Prompt and run the following command to log on to the cluster:
ssh -i <Storage path of the .pem file on your on-premises machine> root@<Public IP address of the master node>
Log on to the cluster by using an SSH password
- Log on from your on-premises machine that runs a Linux operating system
Run the following command in the command-line interface (CLI) of your on-premises machine to connect to the master node:
ssh root@[Public IP address of the master node]
- Log on from your on-premises machine that runs a Windows operating system
- Download and install PuTTY.
Download link: PuTTY.
- Start PuTTY.
- Configure the parameters required to connect to a Linux instance.
- Host Name (or IP address): Specify the fixed public IP address of the instance or the EIP address associated with the instance.
- Port: Enter port number 22.
- Connection type: Select SSH.
- Saved Sessions: optional. Enter a name that helps you identify the session and click Save to save the session. This way, you do not need to enter session information such as the public IP address when you connect to the instance again.
- Click Open.
- Specify the username and press Enter. The default username is root.
The characters of the password are hidden when you enter the password. After you enter the password, press Enter.
- Download and install PuTTY.
FAQ
- Q: How do I log on to a cluster from my on-premises machine in password-free mode?
A: Perform the following steps:
- Open Command Prompt and run the following command to generate a public key:
ssh-keygen
A public key file is generated on your on-premises machine. - Add the generated public key to the master node of the cluster to which you want to
log on.
- Go to the /.ssh directory of the cluster.
cd ~/.ssh
- Edit the key information of the master node of the cluster.
vim authorized_keys
- Add the content of the generated public key file id_rsa.pub to the authorized_keys file.
- Go to the /.ssh directory of the cluster.
- Add the IP address of your on-premises machine to the security group to which the
cluster belongs.
- Obtain the public IP address of your on-premises machine.
For security reasons, we recommend that you allow access only from the current public IP address when you configure a security group rule. To obtain your current public IP address, visit http://myip.ipip.net/.
- Add a security group rule in which port 22 is enabled.
For more information about how to add a security group rule, see Add a security group rule.
- Obtain the public IP address of your on-premises machine.
- Run the following command in Command Prompt to log on to the cluster in password-free
mode:
ssh root@<Public IP address of the master node>
- Open Command Prompt and run the following command to generate a public key:
- Q: How do I log on to a core node?
A: Perform the following steps:
- On the master node, run the following command to switch to the hadoop user:
su hadoop
- Log on to the core node in password-free mode.
ssh emr-worker-1
- Run the following sudo command to obtain the root permissions:
sudo su - root
- On the master node, run the following command to switch to the hadoop user: