216 lines
3.6 KiB
Markdown
216 lines
3.6 KiB
Markdown
|
|
# SSH Access with sshpass
|
||
|
|
|
||
|
|
**Date**: 2025-12-13
|
||
|
|
**Status**: ✅ **CONFIGURED**
|
||
|
|
|
||
|
|
---
|
||
|
|
|
||
|
|
## Overview
|
||
|
|
|
||
|
|
All SSH scripts have been updated to use `sshpass` with the password from `.env` file (lines 45-46).
|
||
|
|
|
||
|
|
---
|
||
|
|
|
||
|
|
## Quick Access Scripts
|
||
|
|
|
||
|
|
### SSH to ML110-01
|
||
|
|
|
||
|
|
```bash
|
||
|
|
./scripts/ssh-ml110-01.sh
|
||
|
|
```
|
||
|
|
|
||
|
|
### SSH to R630-01
|
||
|
|
|
||
|
|
```bash
|
||
|
|
./scripts/ssh-r630-01.sh
|
||
|
|
```
|
||
|
|
|
||
|
|
### Execute Commands Remotely
|
||
|
|
|
||
|
|
```bash
|
||
|
|
# ML110-01
|
||
|
|
./scripts/ssh-ml110-01.sh 'pveversion'
|
||
|
|
./scripts/ssh-ml110-01.sh 'qm list'
|
||
|
|
./scripts/ssh-ml110-01.sh 'pvesm status'
|
||
|
|
|
||
|
|
# R630-01
|
||
|
|
./scripts/ssh-r630-01.sh 'pveversion'
|
||
|
|
./scripts/ssh-r630-01.sh 'qm list'
|
||
|
|
./scripts/ssh-r630-01.sh 'pvesm status'
|
||
|
|
```
|
||
|
|
|
||
|
|
---
|
||
|
|
|
||
|
|
## Manual Commands
|
||
|
|
|
||
|
|
### Using sshpass Directly
|
||
|
|
|
||
|
|
**ML110-01**:
|
||
|
|
```bash
|
||
|
|
PROXMOX_PASSWORD=$(sed -n '45,46p' .env | grep PROXMOX_ROOT_PASS | cut -d'=' -f2 | tr -d '"' | tr -d "'")
|
||
|
|
sshpass -p "$PROXMOX_PASSWORD" ssh root@192.168.11.10
|
||
|
|
```
|
||
|
|
|
||
|
|
**R630-01**:
|
||
|
|
```bash
|
||
|
|
PROXMOX_PASSWORD=$(sed -n '45,46p' .env | grep PROXMOX_ROOT_PASS | cut -d'=' -f2 | tr -d '"' | tr -d "'")
|
||
|
|
sshpass -p "$PROXMOX_PASSWORD" ssh root@192.168.11.11
|
||
|
|
```
|
||
|
|
|
||
|
|
---
|
||
|
|
|
||
|
|
## Password Source
|
||
|
|
|
||
|
|
The password is automatically loaded from `.env` file:
|
||
|
|
- **Location**: Lines 45-46
|
||
|
|
- **Variable**: `PROXMOX_ROOT_PASS`
|
||
|
|
- **Format**: Automatically extracted and cleaned
|
||
|
|
|
||
|
|
---
|
||
|
|
|
||
|
|
## Updated Scripts
|
||
|
|
|
||
|
|
### 1. `scripts/ssh-proxmox-nodes.sh`
|
||
|
|
- Displays SSH commands with sshpass
|
||
|
|
- Shows password status
|
||
|
|
- Provides verification commands
|
||
|
|
|
||
|
|
### 2. `scripts/ssh-ml110-01.sh`
|
||
|
|
- Quick SSH to ML110-01
|
||
|
|
- Password loaded automatically
|
||
|
|
- Supports command execution
|
||
|
|
|
||
|
|
### 3. `scripts/ssh-r630-01.sh`
|
||
|
|
- Quick SSH to R630-01
|
||
|
|
- Password loaded automatically
|
||
|
|
- Supports command execution
|
||
|
|
|
||
|
|
### 4. `scripts/test-proxmox-connectivity.sh`
|
||
|
|
- Uses sshpass for SSH tests
|
||
|
|
- Automatically loads password
|
||
|
|
- Tests both nodes
|
||
|
|
|
||
|
|
---
|
||
|
|
|
||
|
|
## Example Usage
|
||
|
|
|
||
|
|
### Check Proxmox Version
|
||
|
|
|
||
|
|
```bash
|
||
|
|
# ML110-01
|
||
|
|
./scripts/ssh-ml110-01.sh 'pveversion'
|
||
|
|
|
||
|
|
# R630-01
|
||
|
|
./scripts/ssh-r630-01.sh 'pveversion'
|
||
|
|
```
|
||
|
|
|
||
|
|
### List VMs
|
||
|
|
|
||
|
|
```bash
|
||
|
|
# ML110-01
|
||
|
|
./scripts/ssh-ml110-01.sh 'qm list'
|
||
|
|
|
||
|
|
# R630-01
|
||
|
|
./scripts/ssh-r630-01.sh 'qm list'
|
||
|
|
```
|
||
|
|
|
||
|
|
### Check Storage
|
||
|
|
|
||
|
|
```bash
|
||
|
|
# ML110-01
|
||
|
|
./scripts/ssh-ml110-01.sh 'pvesm status'
|
||
|
|
|
||
|
|
# R630-01
|
||
|
|
./scripts/ssh-r630-01.sh 'pvesm status'
|
||
|
|
```
|
||
|
|
|
||
|
|
### Interactive SSH Session
|
||
|
|
|
||
|
|
```bash
|
||
|
|
# ML110-01
|
||
|
|
./scripts/ssh-ml110-01.sh
|
||
|
|
|
||
|
|
# R630-01
|
||
|
|
./scripts/ssh-r630-01.sh
|
||
|
|
```
|
||
|
|
|
||
|
|
---
|
||
|
|
|
||
|
|
## Security Notes
|
||
|
|
|
||
|
|
⚠️ **Important**:
|
||
|
|
- Password is stored in `.env` file (should be in `.gitignore`)
|
||
|
|
- `sshpass` passes password via command line (visible in process list)
|
||
|
|
- For production, consider using SSH keys instead
|
||
|
|
|
||
|
|
### Recommended: Setup SSH Keys
|
||
|
|
|
||
|
|
```bash
|
||
|
|
# Generate key
|
||
|
|
ssh-keygen -t rsa -b 4096 -f ~/.ssh/proxmox_key
|
||
|
|
|
||
|
|
# Copy to both nodes
|
||
|
|
./scripts/ssh-ml110-01.sh 'mkdir -p ~/.ssh && cat >> ~/.ssh/authorized_keys' < ~/.ssh/proxmox_key.pub
|
||
|
|
./scripts/ssh-r630-01.sh 'mkdir -p ~/.ssh && cat >> ~/.ssh/authorized_keys' < ~/.ssh/proxmox_key.pub
|
||
|
|
|
||
|
|
# Then use key-based auth
|
||
|
|
ssh -i ~/.ssh/proxmox_key root@192.168.11.10
|
||
|
|
ssh -i ~/.ssh/proxmox_key root@192.168.11.11
|
||
|
|
```
|
||
|
|
|
||
|
|
---
|
||
|
|
|
||
|
|
## Troubleshooting
|
||
|
|
|
||
|
|
### sshpass Not Installed
|
||
|
|
|
||
|
|
```bash
|
||
|
|
# Ubuntu/Debian
|
||
|
|
sudo apt-get install sshpass
|
||
|
|
|
||
|
|
# RHEL/CentOS
|
||
|
|
sudo yum install sshpass
|
||
|
|
```
|
||
|
|
|
||
|
|
### Password Not Found
|
||
|
|
|
||
|
|
Check `.env` file:
|
||
|
|
```bash
|
||
|
|
sed -n '45,46p' .env
|
||
|
|
```
|
||
|
|
|
||
|
|
Should show:
|
||
|
|
```
|
||
|
|
PROXMOX_ROOT_PASS=L@KERS2010
|
||
|
|
```
|
||
|
|
|
||
|
|
### Connection Issues
|
||
|
|
|
||
|
|
Test connectivity:
|
||
|
|
```bash
|
||
|
|
ping -c 3 192.168.11.10
|
||
|
|
ping -c 3 192.168.11.11
|
||
|
|
```
|
||
|
|
|
||
|
|
Test SSH manually:
|
||
|
|
```bash
|
||
|
|
ssh -v root@192.168.11.10
|
||
|
|
```
|
||
|
|
|
||
|
|
---
|
||
|
|
|
||
|
|
## Conclusion
|
||
|
|
|
||
|
|
✅ **All scripts updated to use sshpass**
|
||
|
|
|
||
|
|
- Password automatically loaded from `.env`
|
||
|
|
- Quick access scripts available
|
||
|
|
- Connectivity tests use sshpass
|
||
|
|
- Ready for automated operations
|
||
|
|
|
||
|
|
---
|
||
|
|
|
||
|
|
**Last Updated**: 2025-12-13
|
||
|
|
**Status**: ✅ **CONFIGURED**
|
||
|
|
|