Type the following commands:
-
ssh-keygen
Press Enter key till you get the prompt
-
ssh-copy-id -i ~/.ssh/id_rsa.pub root@ip_address
(It will once ask for the password of the host system)
-
ssh root@ip_address
Now you should be able to login without any password.
Step 1: Create public and private keys using ssh-key-gen on local-host
jsmith@local-host$ [Note: You are on local-host here] jsmith@local-host$ ssh-keygen Generating public/private rsa key pair. Enter file in which to save the key (/home/jsmith/.ssh/id_rsa):[Enter key] Enter passphrase (empty for no passphrase): [Press enter key] Enter same passphrase again: [Pess enter key] Your identification has been saved in /home/jsmith/.ssh/id_rsa. Your public key has been saved in /home/jsmith/.ssh/id_rsa.pub. The key fingerprint is: 33:b3:fe:af:95:95:18:11:31:d5:de:96:2f:f2:35:f9 jsmith@local-host
Step 2: Copy the public key to remote-host using ssh-copy-id
jsmith@local-host$ ssh-copy-id -i ~/.ssh/id_rsa.pub remote-host jsmith@remote-host's password: Now try logging into the machine, with "ssh 'remote-host'", and check in: .ssh/authorized_keys to make sure we haven't added extra keys that you weren't expecting.
Note: ssh-copy-id appends the keys to the remote-host’s /home/user/.ssh/authorized_key.
Step 3: Login to remote-host without entering the password
jsmith@local-host$ ssh remote-host Last login: Sun Nov 16 17:22:33 2008 from 192.168.1.2 [Note: SSH did not ask for password.] jsmith@remote-host$ [Note: You are on remote-host here]
change the passphrase on your private key:
ssh-keygen -p
examples custom port and custom user:
ssh-copy-id "user@host -p 1234"
ssh-copy-id -i ~/.ssh/id_rsa.pub admin@domain.com -p 1234
root@linux:~# ssh-copy-id -i ~/.ssh/id_rsa.pub admin@remotehost -p 2222
Bad port 'umask 077; test -d ~/.ssh || mkdir ~/.ssh ; cat >> ~/.ssh/authorized_keys'
root@linux:~# cat ~/.ssh/id_rsa.pub | ssh admin@remotehost -p 2222 'umask 077; mkdir -p ~/.ssh; cat >> ~/.ssh/authorized_keys'
The authenticity of host '[remotehost]:2203 ([213.17.25.17]:2203)' can't be established.
RSA key fingerprint is 6e:c5:f3:6e:9a:07:87:28:fc:9f:0d:0d:a1:1a:02:2f.
Are you sure you want to continue connecting (yes/no)? yes
Warning: Permanently added '[remotehost]:2222,[192.164.64.17]:2222' (RSA) to the list of known hosts.
admin@remotehost's password:
root@linux:~#
Generate a ssh key and disable password authentication on the Ubuntu 12.04 (Precise Pangolin) server
RSYNC CRONJOBS EXAMPLES
# Rsync Mirror Backup Directoy to remotepc
30 0 * * * rsync --delete -avzpe ssh /backup/ root@remotepc:/backup/ >> /var/log/syncbackup-remotepc.log
0 1 * * * rsync rsync --delete -azp -e 'ssh -p 22' /backup rsync.domain.com:/home/rsync
*/30 * * * * root /root/cronjobs/mirror.sh >> /tmp/output 2>&1
mirror.sh
#!/bin/bash
echo -e "\n" && date >> /var/log/mirror.log
rsync --delete -avzpe ssh /home/ root@remotepc:/home/ >> /var/log/mirror.log
exit
crontab
00 23 * * 4 root /cronjobs/syncfiles.sh >> /tmp/output 2>&1
syncfiles.sh
#!/bin/bash
mkdir -p /backup
tar -cvpzf /backup/$(date +%Y%m%d-%H%M)_$(hostname)_backupconfigfiles.tgz /etc /root
find /backup/ -type f -mtime +3 -name '*.tgz' -delete
# Script backup files to remote server
BACKUPDIRREMOTE=/backup/$(hostname)
ssh -p 2222 admin@remoteserver "mkdir -p $BACKUPDIR"
rsync -avzpe 'ssh -p 2222' /backup admin@remoteserver:$BACKUPDIRREMOTE
exit
No Comments