Tutorial: Add Hosts
Tutorial: Add Hosts
Section titled “Tutorial: Add Hosts”Learn how to add and configure hosts in SSH-KLM.
Prerequisites
Section titled “Prerequisites”- SSH-KLM instance running
- Admin or Host Manager role
- Network access to target hosts
Method 1: UI (Single Host)
Section titled “Method 1: UI (Single Host)”- Navigate to Hosts → Add Host
- Enter host details:
- Hostname:
server01.example.com - Port:
22 - Labels:
environment: production
- Hostname:
- Click Add Host
- Select discovery method:
- Agent-based (recommended) - Install agent
- Agentless - Provide SSH credentials
Method 2: SDK (Multiple Hosts)
Section titled “Method 2: SDK (Multiple Hosts)”const { QcClient } = require('@qcecuring/ssh-sdk');
const client = new QcClient({ apiKey: process.env.SSHKLM_API_KEY});
const hosts = [ { hostname: 'server01.example.com', labels: { env: 'prod' } }, { hostname: 'server02.example.com', labels: { env: 'prod' } }, { hostname: 'server03.example.com', labels: { env: 'staging' } }];
async function addHosts() { for (const hostData of hosts) { const host = await client.ssh.addHost({ hostname: hostData.hostname, port: 22, labels: hostData.labels }); console.log(`Added: ${host.hostname} (${host.id})`); }}
addHosts();Method 3: Bulk Import (CSV)
Section titled “Method 3: Bulk Import (CSV)”- Prepare CSV file:
hostname,port,environment,teamserver01.example.com,22,production,platformserver02.example.com,22,production,platformserver03.example.com,22,staging,dev- Import via CLI:
ssh-klm hosts import --file hosts.csv --dry-runssh-klm hosts import --file hosts.csvMethod 4: Auto-Discovery
Section titled “Method 4: Auto-Discovery”Configure network scanning:
discovery: networks: - cidr: 10.0.0.0/24 ports: [22, 2222] labels: datacenter: us-east - cidr: 10.0.1.0/24 ports: [22] labels: datacenter: us-westRun discovery:
ssh-klm discovery network --config discovery-config.yamlInstalling the Agent
Section titled “Installing the Agent”After adding hosts, install the agent for full management:
# On the target hostcurl -fsSL https://get.qcecuring.com/ssh-agent | sudo bash -s -- \ --server https://ssh-klm.example.com \ --token HOST_REGISTRATION_TOKENVerifying Host Status
Section titled “Verifying Host Status”// Check host statusconst host = await client.ssh.getHost({ hostId: 'host_abc123'});
console.log(`Status: ${host.status}`);console.log(`Agent: ${host.agentConnected ? 'Connected' : 'Not installed'}`);console.log(`Keys: ${host.keyCount}`);Organizing with Labels
Section titled “Organizing with Labels”Labels help filter and organize hosts:
// Add labels to existing hostawait client.ssh.updateHost({ hostId: 'host_abc123', labels: { environment: 'production', team: 'platform', compliance: 'pci-dss', region: 'us-east-1' }});
// Query by labelsconst prodHosts = await client.ssh.listHosts({ filter: { labels: { environment: 'production' } }});