How to use ssh-config - 10 common examples

To help you get started, we’ve selected a few ssh-config examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github NickCarneiro / remtail / lib / creds.js View on Github external
function parseSshConfig(sshConfigFileContents) {
    // Previously we were using a library that parsed ssh config files into arrays.
    // Mimic that behavior here so the rest of the code doesn't need to change.
    return objectToArray(sshConfig.parse(sshConfigFileContents));
}
github sebas5384 / hades / app / lib / ConfigFile.js View on Github external
const loadFromLocal = () => {
    const managedConfig = readManagedLocalConfig()
    const config = sshConfig.parse(managedConfig)

    // Return an empty array in case the local file is empty.
    if (!0 in config) return []

    // Extract items.
    const items = Object.keys(config)
      .filter((key) => {
        const index = Number(key)
        return Number.isInteger(index)
      })
      .map((key) => config[key])
      .map((item) => convertToAppFormat(item))

    return items
  }
github sebas5384 / hades / app / lib / ConfigFile.js View on Github external
const update = (items) => {

    const newConfig = sshConfig.parse('')
    // Convert items to the config format and append to the new config.
    items.forEach((item) => {
      const convertedItem = convertToConfigFormat(item)
      newConfig.append(convertedItem)
    })

    const newConfigString = sshConfig.stringify(newConfig);

    const unmanagedConfig = readUnmanagedLocalConfig()

    return unmanagedConfig
      .trim()
      .concat("\n", settings.startTag)
      .concat("\n", newConfigString)
      .concat("\n", settings.endTag)
  }
github derimagia / sshconfig2iterm / cli.js View on Github external
fs.readFile(process.env.HOME + '/.ssh/config', function (err, data) {
  if (err) {
    throw err;
  }

  sshConfig = sshConfig.parse(data.toString());

  var output = {
    Profiles: [],
  };

  for (var i = 0, len = sshConfig.length; i < len; i++) {
    var section = sshConfig[i];

    var host = section.Host;

    var comment = null;
    var commentIndex = section.Host.indexOf('#');

    if (commentIndex !== -1) {
      host = section.Host.substr(0, commentIndex);
      comment = section.Host.substr(commentIndex + 1).trim();
    }
    var host = host.trim();

    // Skip Wildcard Entries
    if (host.indexOf('*') != -1) continue;
github ionic-team / ionic-cli / packages / ionic / src / lib / __tests__ / ssh-config.ts View on Github external
it('should stringify with config5 file', async () => {
        const config5 = await readFile(path.resolve(__dirname, 'fixtures/ssh-config/config5'), { encoding: 'utf8' });
        const conf = SSHConfig.parse(config5);
        ensureHostAndKeyPath(conf, { host: 'bar' }, '/id_rsa');
        expect(SSHConfig.stringify(conf)).toEqual(config5);
      });
github ionic-team / ionic-cli / packages / ionic / src / lib / __tests__ / ssh-config.ts View on Github external
it('should stringify with config3 file', async () => {
        const config3 = await readFile(path.resolve(__dirname, 'fixtures/ssh-config/config3'), { encoding: 'utf8' });
        const conf = SSHConfig.parse(config3);
        ensureHostAndKeyPath(conf, { host: 'bar' }, '/id_rsa');
        expect(SSHConfig.stringify(conf)).toEqual(config3);
      });
github microsoft / vscode-pull-request-github / src / common / ssh.ts View on Github external
export function resolverFromConfig(text: string): ConfigResolver {
	const config = parseConfig(text);
	return h => config.compute(h.Host);
}
github ionic-team / ionic-cli / packages / cli-plugin-cloud / src / commands / ssh / use.ts View on Github external
ensureSection(conf: SSHConfig.SSHConfig, host: string, newline: boolean): SSHConfig.ConfigDirective {
    const section = conf.find({ Host: host });

    if (!section) {
      conf.push(SSHConfig.parse(`${newline ? '\n' : ''}Host ${host}\n`)[0]);
    }

    return conf.find({ Host: host });
  }
github ionic-team / ionic-cli / packages / cli-plugin-cloud / src / commands / ssh / use.ts View on Github external
async applyConfig(text: string, keyPath: string): Promise {
    const c = await this.config.load();
    const conf = SSHConfig.parse(text);
    const host = c.git.host;
    const section = this.ensureSection(conf, host, Boolean(text));

    this.ensureSectionLine(section, 'IdentityFile', keyPath);

    if (typeof c.git.port === 'number') {
      this.ensureSectionLine(section, 'Port', String(c.git.port));
    }

    return SSHConfig.stringify(conf);
  }
github ionic-team / ionic-cli / packages / ionic / src / lib / ssh-config.ts View on Github external
export async function loadFromPath(p: string): Promise {
  const s = await fileToString(p);

  return SSHConfig.parse(s);
}

ssh-config

SSH config parser and stringifier

MIT
Latest version published 27 days ago

Package Health Score

78 / 100
Full package analysis