The Blog

Linux

RSYNC over ssh with sudo to preserve permissions and ownership

Posted on

See this post first as it’s the first step to this setup:
Steps to Perform SSH Login Without Password Using ssh-keygen & ssh-copy-id

#sudo visudo on the terget box

at the bottom add:

username_that_logs_in_to_ssh_from_source ALL=NOPASSWD: /usr/bin/rsync

to your rsync command add:

--rsync-path="sudo rsync"

full example:

rsync -avz --delete --rsync-path="sudo rsync" /var/www/sites/ target_host:/var/www/sites/
Posted in Linux 1 Comment

Steps to Perform SSH Login Without Password Using ssh-keygen & ssh-copy-id

Posted on

You can login to a remote Linux server without entering password in 3 simple steps using ssky-keygen and ssh-copy-id as explained in this article.

ssh-keygen creates the public and private keys. ssh-copy-id copies the local-host’s public key to the remote-host’s authorized_keys file. ssh-copy-id also assigns proper permission to the remote-host’s home, ~/.ssh, and ~/.ssh/authorized_keys.

This article also explains 3 minor annoyances of using ssh-copy-id and how to use ssh-copy-id along with ssh-agent.

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 .ssh/authorized_key.
Use this command to remove entries from known_hosts:

ssh-keygen -R hostname

You will also have to remove those entries from authorized_keys

Posted in Linux, Networking Leave a comment

SSHD slow on login

Posted on

Does the IP you’re connecting from have reverse DNS on it?

When you connect to SSH, By default it will try to do a DNS lookup on the IP connecting and if it can’t find a record it causes a long delay when logging in.

If you want you can disable sshd from doing a reverse lookup by setting

UseDNS no

In /etc/ssh/sshd_config and restarting sshd.

service sshd restart

Posted in Linux Leave a comment

Shell du command tip – estimate file space usage and

Posted on

The du command estimate file space usage and summarize disk usage of each
FILE, recursively for directories.

It displays the file system block usage for each file argument and for each
directory in the file hierarchy rooted in each direc tory argument. If no file
is specified it will use current directory.

But why use du command?

You must be wondering why I’m throwing out a light on du command. du is
commonly used by system administrators to automate monitoring and notification
programs that help prevent directories from becoming full.

du command ExamplesRead More

Posted in Linux Leave a comment
« Previous Page