How to make SSH connections on macOS machine

Configurare noua (How To)

Situatie

The only thing you’ll need is a MacBook or iMac that includes SSH and some remote servers to connect to.

Solutie

Open the macOS terminal app. Once it opens, change into your user SSH directory with the command:

cd ~/.ssh

In that directory, create the new file with the command:

nano config

Let’s create our first configuration. For example, say this is a Nextcloud server at IP address 192.168.1.20 and the username is vega. We’re going to name this server “nextcloud” so we can easily remember how to Secure Shell into it. We’re also going to enable key authentication for the connection.

This configuration will look like:

Host nextcloud
   HostName 192.168.1.20
   User vega
   IdentityFile ~/.ssh/id_rsa.pub

If you’re not using SSH KEY authentication (which you should), you’d need to remove the IdentityFile line. Save and close the file.

To SSH into our Nextcloud server, you’d only have to type the command:

ssh nextcloud

You can create as many configurations in that file as you need (one for every server in your data center), each with different options. Just make sure, at a minimum, you include the Host and Hostname options. This makes it so much easier for you to remote into those servers from your Apple laptop or desktop.

Let’s say you use the same account on all of your data center servers on the IP address scheme 192.168.1.x. You could configure that at the top of the config file with two simple lines:

Host 192.168.1.*
User USERNAME

Where USERNAME is the user on the remote machines.

You could then create each host configuration entry (below that), leaving out the User option, like so:

Host nextcloud
   HostName 192.168.1.20
   IdentityFile ~/.ssh/id_rsa.pub

Host web1
   HostName 192.168.1.25

Host db1
   HostName 192.168.1.100
   IdentityFile ~/.ssh/db_rsa.pub

Save the file and you’re ready to SSH into those machines with commands like:

ssh nextcloud
ssh web1
ssh db1
Use Your SSH Config File to Create Aliases for Hosts

And that’s all there is to creating an SSH config file to be used on macOS.

Tip solutie

Permanent

Voteaza

(3 din 7 persoane apreciaza acest articol)

Despre Autor

Leave A Comment?