Posts

Showing posts with the label ssh

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: ...

Keeping Your SSH Connections Alive: Configuring ServerAliveInterval and ServerAliveCountMax

Image
Maintaining a stable SSH connection is essential when working on remote servers. Disconnections due to inactivity can interrupt workflows and be quite frustrating. Fortunately, you can configure SSH to send periodic keep-alive messages, preventing your connection from timing out. Step-by-Step Guide 1. Open the SSH Client Configuration File Use your preferred text editor to modify the SSH configuration file. For example, with  vim : sudo vim /etc/ssh/ssh_config If OpenSSH is installed via Homebrew, the configuration file might be located at: /usr/ local /etc/ssh/ssh_config 2. Modify the Configuration Add the following lines after the  Host *  directive to apply these settings to all SSH connections: ServerAliveInterval 240 ServerAliveCountMax 10 ServerAliveInterval : Specifies the interval (in seconds) at which the client sends keep-alive messages to the server. In this case, every 240 seconds. ServerAliveCountMax : Limits the number of keep-alive messages sent w...

SSH Security Configuration for Servers

Image
Introduction Secure Shell (SSH) is a crucial component for remote access to Server Instance, and its configuration should be optimized to ensure the highest level of security. Given the role SSH plays in facilitating secure communication and access to servers, it is strongly recommended to implement robust security measures to protect sensitive data and prevent unauthorized access to these Servers. The current configuration enforces the following security measures: Dedicated terminal-user Root login is disabled Host-based authentication is disabled Empty passwords are disabled Public-Key Authentication is enabled Max-auth attempts is set to 5 Idle-Timeout is set to 5 minutes X11 Forwarding is disabled Port Forwarding is disabled Max concurrent sessions is set to 5 Log level is set to verbose (audit trail) Warning banner is set to scare-of threat-actors First Steps Before applying the config file mentioned below, make sure to take the foll...