Posts

Showing posts with the label identity file

Using Custom SSH Keys with Git Push: How to Deploy Securely with -i

🔐 How to Use  -i  (Identity File) with  git push When deploying to a remote server using  git push , you might want to use a custom SSH key instead of the default one. While you  can’t pass  -i  directly to  git push , you can configure it through SSH in one of the following ways: 🔹 Option 1: Use  GIT_SSH_COMMAND  (Simple and Temporary) Run the following command: GIT_SSH_COMMAND= 'ssh -i /path/to/private_key' git push production master ✅ This sets a temporary SSH command that uses your custom key,  just for this  git push . 🔹 Option 2: Add a Permanent Entry in  ~/.ssh/config Edit your SSH configuration: nano ~/.ssh/config Add the following: Host your-server-alias HostName your-server User sshuser IdentityFile /path/to/private_key IdentitiesOnly yes Then update your Git remote to use the alias: git remote set -url production ssh://your-server-alias/home/sshuser/repos/myapp.git ✅ Now, every time you run: ...