Hadoop3.0.0伪分布式启动报错求助:localhost权限拒绝及配置异常
Hey Tim, let's work through these two issues step by step to get your Hadoop pseudo-distributed cluster up and running smoothly.
1. Fix the #: command not found error in hadoop-env.sh
This error pops up because your hadoop-env.sh script's first line is being interpreted as a command instead of a comment. The most common causes are:
- You used a full-width Chinese
#instead of the standard half-width English#for comments - The script lacks a proper shebang (the line that tells the system which shell to use) at the top
Resolution steps:
- Open the file for editing:
sudo nano /usr/local/hadoop/etc/hadoop/hadoop-env.sh - Check the first line:
- If it's a comment, make sure it starts with a half-width
#(e.g.,# Hadoop Environment Configuration) - If it's a shebang line, set it to
#!/bin/bash(the standard for bash scripts)
- If it's a comment, make sure it starts with a half-width
- Save and exit: Press
Ctrl+O, hit Enter, thenCtrl+X
2. Resolve localhost: Permission denied (publickey,password)
Hadoop's pseudo-distributed mode requires password-less SSH access to localhost for node communication. This error means your user tc doesn't have the right SSH permissions set up.
Resolution steps:
Step 1: Generate an SSH key pair (if you haven't already)
Run this command and press Enter through all prompts to accept defaults:
ssh-keygen -t rsa -P ""
This creates two files in ~/.ssh/: id_rsa (private key) and id_rsa.pub (public key).
Step 2: Add your public key to authorized keys
Append your public key to the list of trusted keys:
cat ~/.ssh/id_rsa.pub >> ~/.ssh/authorized_keys
SSH enforces strict permissions for these files, so set the correct access rights:
chmod 600 ~/.ssh/authorized_keys chmod 700 ~/.ssh
Step 3: Test password-less login
Verify the setup works by logging into localhost without a password:
ssh localhost
If you get a shell prompt without entering a password, it's working. Type exit to return to your original session.
Final Verification
Once both fixes are done, re-run the start command:
sudo /usr/local/hadoop/sbin/start-dfs.sh
Use the jps command to check running processes—you should see NameNode, DataNode, and SecondaryNameNode listed if everything started correctly.
内容的提问来源于stack exchange,提问作者Tim

