KandZ – Tuts

We like to help…!

Linux CLI 33 🐧 ssh command

a - ssh command

ssh (Secure Shell) is a command that connects to a remote server
It is secure and it does not share your password.
You can log into a Linux or Unix system and execute commands on it.
ssh user@hostname → user is the username from the remote system.
instead of hostname you can also use an IP address
install ssh Server and client
RedHat based → sudo yum install openssh-clients openssh-server

or sudo dnf install openssh-clients openssh-server

Debian/Ubuntu → sudo apt install openssh-client openssh-server


b - ssh login with SSH Key Pair

You can login to a remote system without password use.
You have to create an SSH key pair. Follow the instructions
ssh-keygen -t rsa → creates the key pair
Press enter when prompted for a file name and location, leaving the defaults as is (just hit enter)

→ Enter a passphrase when prompted (this will be used to encrypt your private key).

You will then be prompted to confirm the passphrase. → Press enter again to continue.
Copy the contents of the `id_rsa.pub` file (your public key) to a server you want to access.
cat ~/.ssh/id_rsa.pub | ssh user@hostname "mkdir -p .ssh && chmod 700 .ssh && cat .ssh/authorized_keys"
replace user with your user and hostname with the remote system hostname/IP address

Leave a Reply