HomeVS Code / Dev EnvWindows 11でSSH鍵を作成する(VSCodeからGitHubにアクセスするための準備)
Windows11でSSH鍵を作成する(VSCodeからGitHubにアクセスするための準備)

Windows 11でSSH鍵を作成する(VSCodeからGitHubにアクセスするための準備) This guide walks through generating SSH keys on Windows 11, registering them with GitHub, …

元記事を読む 鮮度 OK
AI 3 行サマリ
  • Windows 11でSSH鍵を生成してGitHubに登録し、VSCodeからリポジトリへ安全に接続できる環境を整える手順をまとめた実践的なガイド。
  • 開発環境を初めて構築する人に役立つ内容となっている。
English summary
  • This guide walks through generating SSH keys on Windows 11, registering them with GitHub, and configuring VSCode for secure repository access, making it straightforward for developers to establish a reliable local workflow.

Windows 11の環境でSSH鍵を生成し、GitHubに登録したうえでVSCodeからリポジトリへ安全に接続する——。開発を始めたばかりの人がつまずきやすいこの初期設定を、順を追って解説する実践的なガイドが公開された。ローカルの開発ワークフローを確立するための土台となる内容だ。

背景には、GitHubが2021年8月にパスワードによるGit操作の認証を廃止した経緯がある。現在、コマンドラインからのアクセスにはSSH鍵か個人アクセストークン(PAT)のいずれかが必要で、日常的にpushやpullを繰り返す用途ではSSH鍵を用いる方式が広く選ばれている。一度設定すれば認証情報を都度入力する手間がなく、公開鍵暗号方式によって安全性も高い。

鍵の生成にはOpenSSHに含まれるssh-keygen">ssh-keygenコマンドを使う。Windows 11ではOpenSSHクライアントが標準で同梱されているため、追加インストールなしにPowerShellやターミナルからそのまま実行できる。鍵の種類としては、従来広く使われてきたRSAに加え、より短い鍵長で高い安全性と速度を両立するEd25519が近年推奨される傾向にある。生成された公開鍵(拡張子.pub)の内容をGitHubの設定画面にあるSSH keysの項目へ貼り付けることで、アカウントと鍵が紐づけられる。

Windows 11でSSH鍵を生成してGitHubに登録し、VSCodeからリポジトリへ安全に接続できる環境を整える手順をまとめた実践的なガイド。
🔷 VS Code / Dev Env · 本記事のポイント

VSCode側では、標準のGit連携機能やソース管理ビューを通じてSSH経由のリモートリポジトリを扱える。クローンやコミット、プッシュといった操作をエディタ上で完結でき、ターミナルとGUIを行き来する負担が減る。GitLensなどの拡張機能を組み合わせれば、変更履歴の把握もしやすくなるだろう。

なお、認証まわりの選択肢はSSH鍵だけではない。GitHub CLIを使えば対話的な認証でトークンを自動管理でき、HTTPS接続を好む場合はGit Credential Managerが資格情報を保存する仕組みも用意されている。用途や好みに応じて方式を選べるが、SSH鍵の作成と登録は多くの開発者にとって基本となる知識であり、一度理解しておけばGitHubに限らず他のGitホスティングサービスでも応用が利く。

Setting up SSH key authentication is one of the first tasks many developers face when preparing a new machine, and doing it correctly on Windows 11 removes a recurring source of friction when working with GitHub through Visual Studio Code. Since GitHub retired password authentication for Git operations in August 2021, developers must rely on either personal access tokens over HTTPS or SSH keys to push and pull code. SSH keys are widely favored because, once configured, they allow secure connections without repeatedly entering credentials.

At its core, SSH key authentication uses a pair of cryptographically linked files. The private key remains on your local machine and must never be shared, while the public key is uploaded to GitHub. When you connect, GitHub issues a challenge that only the matching private key can answer, proving your identity without transmitting a password. This asymmetric approach is both more convenient and generally more resistant to credential theft than reusable passwords.

Windows 11 simplifies the process because it ships with the OpenSSH client enabled by default, so there is no need to install PuTTY or third-party tools as was common in earlier Windows eras. You can generate a key from PowerShell or the terminal using the ssh-keygen">ssh-keygen command. The recommended approach is to create an Ed25519 key, for example by running ssh-keygen">ssh-keygen -t ed25519 -C "your_email@example.com". Ed25519 is a modern elliptic-curve algorithm that offers strong security with shorter keys and faster performance than the older RSA standard, though RSA with at least 4096 bits remains a valid fallback for systems that do not support Ed25519.

During generation, ssh-keygen">ssh-keygen prompts for a file location, defaulting to a .ssh folder inside your user profile, and for an optional passphrase. Adding a passphrase encrypts the private key at rest, providing an extra layer of protection if the file is ever exposed. The tradeoff is that you must enter the passphrase when the key is used, though the ssh-agent service can cache it for the session. On Windows 11, you can start this service and add your key so you are not prompted repeatedly.

Once the key pair exists, the next step is registering the public key with GitHub. You copy the contents of the .pub file and paste it into the SSH and GPG keys section of your GitHub account settings. It is important to copy only the public key and never the private counterpart. After saving, you can verify the connection by running ssh -T git@github.com, which should return a message confirming your username while noting that GitHub does not provide shell access.

With authentication working at the system level, Visual Studio Code benefits automatically because it uses the same underlying Git and SSH configuration. VSCode does not manage SSH keys itself; instead, it relies on the Git executable and the operating system's SSH setup. This means that cloning a repository using its SSH URL, which begins with git@github.com, will authenticate through the key you created. The built-in Source Control panel then handles staging, committing, pushing, and pulling without further credential prompts. For projects with multiple accounts or hosts, an SSH config file in the .ssh directory can define host aliases and specify which key to use for each.

It is worth understanding the alternatives to place this workflow in context. HTTPS combined with a personal access token and the Git Credential Manager, which is bundled with Git for Windows, is another supported path and is sometimes easier for beginners. The GitHub CLI, invoked as gh, can also handle authentication and can even generate and upload SSH keys during its login flow. Meanwhile, the Remote-SSH extension for VSCode uses these same keys for an entirely different purpose, connecting the editor to remote servers, which illustrates how broadly SSH knowledge transfers.

For anyone building a development environment from scratch, treating SSH setup as a foundational step pays dividends. The private key should be backed up securely and never committed to a repository, and rotating or revoking keys through GitHub settings is straightforward if a machine is lost. Once in place, the configuration is durable, and the combination of Windows 11's native OpenSSH support and VSCode's integrated tooling makes a reliable, low-maintenance local workflow accessible to newcomers and experienced developers alike.

  • SourceQiita VSCode tagT2
  • Source Avg ★ 1.1
  • Typeブログ
  • Importance ★ 情報 (lower priority in VS Code / Dev Env)
  • Half-life 📘 中期 (チュートリアル)
  • LangJA
  • Collected2026/07/04 13:00

本ページの本文・要約は AI による自動生成です。正確性は元記事 (qiita.com) をご確認ください。

🔷 VS Code / Dev Env の他の記事 もっと見る →

URL をコピーしました