{
    "content": "<h1>Understanding the .config\/gh\/hosts.yml File<\/h1><p>The <code>.config\/gh\/hosts.yml<\/code> file serves as the central repository for authentication metadata used by the <a href=\"..\/github-cli\/\">GitHub CLI<\/a>, commonly referred to by its command-name <a href=\"..\/gh\/\">gh<\/a>. This configuration file is responsible for storing the state of user sessions across different <a href=\"..\/github\/\">GitHub<\/a> environments, including the public cloud and private <a href=\"..\/github-enterprise-server\/\">GitHub Enterprise Server<\/a> instances. On most <a href=\"..\/linux\/\">Linux<\/a> and <a href=\"..\/macos\/\">macOS<\/a> systems, the file is located within the user's home directory at <code>~\/.config\/gh\/hosts.yml<\/code>, while on Windows, it is typically found in the <code>%AppData%\\gh\\<\/code> directory.<\/p><p>The internal structure of the file follows the <a href=\"..\/yaml\/\">YAML<\/a> serialization standard. It organizes data by hostname, where each host entry contains specific keys such as <code>user<\/code>, <code>oauth_token<\/code>, and <code>git_protocol<\/code>. The <code>oauth_token<\/code> is a sensitive <a href=\"..\/authentication-token\/\">authentication token<\/a> that allows the <a href=\"..\/gh\/\">gh<\/a> tool to perform actions on behalf of the user via the <a href=\"..\/github-api\/\">GitHub API<\/a>. The <code>git_protocol<\/code> entry determines whether the CLI should use <a href=\"..\/ssh\/\">SSH<\/a> or <a href=\"..\/https\/\">HTTPS<\/a> when performing <a href=\"..\/git\/\">git<\/a> operations like cloning or pushing. Because this file contains plain-text credentials, it is highly recommended to ensure that file permissions are restricted to the owner only.<\/p><p>While users can manually edit this file, it is primarily managed through the <a href=\"..\/gh-auth\/\">gh auth<\/a> suite of commands. For instance, running <code>gh auth login<\/code> will automatically update the <code>hosts.yml<\/code> file with a new <a href=\"..\/oauth\/\">OAuth<\/a> session. For further reading on managing credentials and host configurations, consult the <a href=\"https:\/\/cli.github.com\/manual\/gh_auth\">Official GitHub CLI Manual<\/a>.<\/p><ul><li><a href=\"..\/gh-auth-login\/\">gh-auth-login<\/a><\/li><li><a href=\"..\/config-yml\/\">config.yml<\/a><\/li><li><a href=\"..\/personal-access-tokens\/\">personal-access-tokens<\/a><\/li><li><a href=\"..\/environment-variables\/\">environment-variables<\/a><\/li><\/ul>",
    "tags": [
        "github-cli",
        "gh",
        "yaml",
        "configuration",
        "authentication",
        "security",
        "git",
        "devops",
        "cli",
        "github"
    ]
}