Configure SSH to avoid prompting for a password each time.
Currently, after setting up SSH with a PEM file, you can access a server without a password like so:
ssh -i "ohio.pem" [email protected]However, when a user is created on the remote server with a password (e.g., user devops), SSH prompts for a password every time you log in:
ssh [email protected]
EnterPassword:We need to configure the local machine to stop asking for the password each time without changing anything on the remote server.
Create or edit the SSH configuration file located at ~/.ssh/config:
nano ~/.ssh/configAdd the following configuration:
Host 3.19.xx.xx
HostName 3.19.xx.xx
User ubuntu
PreferredAuthentications password
IdentityFile none
Check your current shell with:
echo $SHELLDepending on the shell, configuration files differ:
- Bash:
~/.bashrc - Zsh:
~/.zshrc - Fish:
~/.config/fish/config.fish
Since the shell in use is Zsh, configure the .zshrc file:
nano ~/.zshrcAdd the following alias at the end of the file:
# ssc command alias
alias ssc='sshpass -p123 ssh'Note: Replace
123with the actual password of userdevops.
Reload the shell configuration:
source ~/.zshrcTest the SSH connection with the alias:
ssc 3.19.xx.xx # First time, it asks for the password.Exit and log in again:
ssc 3.19.xx.xx # This time, login without prompt.- known_hosts: Located at
~/.ssh/known_hosts, this file contains public keys of remote servers used to verify their identity during connections. - Config File: The SSH configuration file (
~/.ssh/config) allows customization of connection settings for various hosts.
By following these steps, you can ensure that SSH connections do not prompt for passwords repeatedly while maintaining existing remote server configurations.