1

I routinely backup my books to another computer within the same wifi,

rsync -avlu --exclude=".git" ~/Documents/Books beta@192.168.31.90:~/Documents/Books
rsync -avlu --exclude={.git,.DS_Store}" ~/Documents/Books beta@192.168.31.90:~/Documents/Books

Everytime, I should remember the ip address of destination machine.

Tried @local and @localhost but failed.

How could I use a name rather than a series of numbers?

pa4080
  • 29,831
Alice
  • 1,710
  • I made Truck.app (an rsync app) to make this easier. Excuse the shameless plug but perhaps it will help you -> http://bonhardcomputing.com/truck/ – dave Mar 20 '19 at 01:45

2 Answers2

3

For this purpose you need to setup ~/.ssh/config file:

touch ~/.ssh/config
chmod 600 ~/.ssh/config

The content of the file should look as:

Host my-destination-host
    HostName 192.168.31.90
    IdentityFile ~/.ssh/id_rsa
    User beta
    Port 22

Host another-example
    HostName 222.222.22.222
    User another-user
    IdentityFile ~/.ssh/another-path/id_rsa
    Port 2233
    RemoteForward 6900 127.0.0.1:5900
    RemoteForward 3389 192.168.100.115:3389
    Compression yes
    CompressionLevel 6

# etc.

Once the file is saved, you will be able to ssh to beta@192.168.31.90 by the command:

ssh my-destination-host

or for the another example - note the Tab completion is applicable for the Host names:

ssh another-exampTab ↹

Respectively most of the commands that use ssh can use the configuration file. For example rsync:

rsync -avlu --exclude=".git" ~/Documents/Books my-destination-host:~/Documents/Books

References and more examples, where the ~/.ssh/config file is used:

pa4080
  • 29,831
0

Why not just use the 'dot local' hostname?

rsync -avlu --exclude=".git" ~/Documents/Books beta@my-machine.local:~/Documents/Books

On the receiving machine, go to System Preferences -> Sharing. Next to 'computer name' click 'edit'. Then copy the address. Mine, for instance, is 'terminal-36.local'.

Also consider specifying --rsh=/usr/bin/ssh -o AddressFamily=inet. Resolving .local hostnames to IPv6 has always caused me bother (but perhaps you'll be luckier).

dave
  • 101