Home About

Bash Shell Tips - ssh

Created //

Tags // linux, shell, scripts, bash, ssh

The ssh command

Use the ssh command to login to other servers.

Update: 2023

This isn't something I have much need for these days, given the prevalence of serverless hosting, AWS, etc.

But, it's still worth having a basic understanding for administering your own local machines.

Login to the machine at ip address 192.168.123.234 with the username myusername

$ ssh myusername@192.168.123.234

You'll be prompted to enter for the password for user myusername on the machine at 192.168.123.234.

Setup password-less login for a remote machine

Create an ssh key. You can choose whether you want a passphrase or not. For a password-less login, do not enter a passphrase. But also understand that means if someone gets access to the key, they can login to the remote machine without a password.

$ ssh-keygen -t rsa

This will create a private key (e.g., ~/.ssh/id_rsa) and a public key (e.g., ~/.ssh/id_rsa.pub).

You're going to copy the public key to the remote machine.

Copy the key to the remote machine. You'll be asked for the password for user myusername on the server 192.168.123.234.

$ ssh-copy-id -i ~/.ssh/id_rsa.pub myusername@192.168.123.234

After this, you should be able to login to the server without a password. Test it with:

$ ssh myusername@192.168.123.234

You should be able to login immediately, either without a password prompt, or for a passphrase if you created one.

This also applies to other commands you might want to run on the remote server (e.g., scp for copying files).

Learn how to use ssh

Remember, most unix/linux commands already have documentation built into the operating system.

$ man ssh

... will show the documentation for ssh.

// ka

You might also be interested in...