树莓派VNC登录失败与SSH启动报错问题求助
Hey there, let's work through these two problems step by step—both the SSH initialization errors and the VNC login loop are common issues with straightforward fixes once we narrow down the root causes.
Fixing SSH Errors: -bash: id: command not found & -bash: [: : integer expression expected
These errors usually boil down to either a broken system utility package or misconfigured shell environment variables/startup scripts. Here's how to fix them:
1. Verify & Restore the id Command
The id command is part of the coreutils package. First, check if the command exists at its standard path:
/usr/bin/id
- If this outputs your user info, the problem is that your
$PATHvariable is missing critical directories. Fix it temporarily with:
Log out and back in to see if the error disappears. To make this permanent, add the line above to yourexport PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin~/.profilefile. - If
/usr/bin/iddoesn't exist, yourcoreutilspackage is corrupted. Reinstall it using the absolute path forapt-get:/usr/bin/apt-get install --reinstall coreutils
2. Fix the Integer Expression Error
This error happens when a shell script (like your ~/.bashrc or ~/.profile) tries to run a numeric comparison with an empty variable. To troubleshoot:
- Temporarily disable your user-specific startup scripts to test:
Log out and back in—if the error is gone, you know the issue is in one of these files. Open the backed-up files and look for lines likemv ~/.bashrc ~/.bashrc.bak mv ~/.profile ~/.profile.bak[ $SOME_VAR -eq 0 ]whereSOME_VARmight be empty. Add a check to ensure the variable is set before comparing, or fix how the variable is assigned.
Fixing VNC Login Loop (Black Screen → Login Screen Cycle)
This is almost always a permission issue, corrupted desktop configuration, or misconfigured VNC startup script. Try these steps:
1. Check VNC Server Status
First, confirm the VNC service is running without critical errors. For the official RealVNC server:
systemctl status vncserver-x11-serviced
For TightVNC:
systemctl status tightvncserver
Look for error messages in the output—if the service isn't starting, address those first (e.g., missing dependencies).
2. Reset VNC & User Directory Permissions
Incorrect permissions on your ~/.vnc folder or user directory can prevent the desktop from loading. Fix them with:
chown -R $USER:$USER ~/.vnc chmod -R 755 ~/.vnc
Then restart the VNC service:
# For RealVNC systemctl restart vncserver-x11-serviced # For TightVNC systemctl restart tightvncserver
3. Reset Corrupted Desktop Configuration
If your Pixel (or other desktop environment) config is broken, reset it by renaming the config folder:
# For Pixel desktop mv ~/.config/lxsession ~/.config/lxsession.bak
Restart the VNC service and try logging in again—this will generate a fresh default configuration.
4. Fix VNC Startup Script
If your xstartup script is misconfigured, the desktop won't launch properly. Edit the file:
nano ~/.vnc/xstartup
Make sure it has these lines (for Pixel desktop):
#!/bin/sh xrdb $HOME/.Xresources startlxde-pi &
Save the file (Ctrl+O, Enter) and exit (Ctrl+X), then make it executable:
chmod +x ~/.vnc/xstartup
Restart the VNC service and test again.
5. Reinstall VNC Server as a Last Resort
If nothing else works, wipe and reinstall the VNC server:
# For RealVNC apt-get purge realvnc-vnc-server realvnc-vnc-viewer apt-get install realvnc-vnc-server # For TightVNC apt-get purge tightvncserver apt-get install tightvncserver
After reinstalling, reconfigure the VNC server using the vncserver command.
内容的提问来源于stack exchange,提问作者Shay Yzhakov

