Skip to content

Tutorial: Add Hosts

Learn how to add and configure hosts in SSH-KLM.

  • SSH-KLM instance running
  • Admin or Host Manager role
  • Network access to target hosts
  1. Navigate to Hosts → Add Host
  2. Enter host details:
    • Hostname: server01.example.com
    • Port: 22
    • Labels: environment: production
  3. Click Add Host
  4. Select discovery method:
    • Agent-based (recommended) - Install agent
    • Agentless - Provide SSH credentials
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();
  1. Prepare CSV file:
hostname,port,environment,team
server01.example.com,22,production,platform
server02.example.com,22,production,platform
server03.example.com,22,staging,dev
  1. Import via CLI:
Terminal window
ssh-klm hosts import --file hosts.csv --dry-run
ssh-klm hosts import --file hosts.csv

Configure network scanning:

discovery-config.yaml
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-west

Run discovery:

Terminal window
ssh-klm discovery network --config discovery-config.yaml

After adding hosts, install the agent for full management:

Terminal window
# On the target host
curl -fsSL https://get.qcecuring.com/ssh-agent | sudo bash -s -- \
--server https://ssh-klm.example.com \
--token HOST_REGISTRATION_TOKEN
// Check host status
const 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}`);

Labels help filter and organize hosts:

// Add labels to existing host
await client.ssh.updateHost({
hostId: 'host_abc123',
labels: {
environment: 'production',
team: 'platform',
compliance: 'pci-dss',
region: 'us-east-1'
}
});
// Query by labels
const prodHosts = await client.ssh.listHosts({
filter: {
labels: {
environment: 'production'
}
}
});