Tips for managing remote hosts

Source: Internet
Author: User
Tags free ssh rsync

Article Source: http://www.everet.org/2012/01/management-remote-host.html reprint please keep the link, thank you.

For remote host management, I think SSH is generally used. In a Linux environment, it is very convenient and can be used without any need.

Ssh-l username hostname

To log on to the remote host. On Windows, although there is a dedicated SSH client, it is very friendly in cygwin. For cygwin, we can set OpenSSH to be selected during installation so that SSH can be easily used on Windows. Of course, there are many great tools to install, in China, the speed of selecting 163 images is quite fast.

Password required for every login? Password-free SSH Login!

We can create a public key and a secret key to achieve password-free login. The public key is placed on the server, so that you do not need to enter a password as long as the Public Key matches correctly during login.

Now, let's create the public key and key. We use SSH-keygen to generate the key.

$ ssh-keygenGenerating public/private rsa key pair.Enter file in which to save the key (/home/Cedric Porter/.ssh/id_rsa):Enter passphrase (empty for no passphrase):Enter same passphrase again:Your identification has been saved in id_rsa_test.Your public key has been saved in id_rsa_test.pub.The key fingerprint is:60:7c:f3:42:58:57:42:1f:dc:65:e2:05:3d:49:54:02 Cedric Porter@CedricPorter-PCThe key's randomart image is:+--[ RSA 2048]----+|        ..+oEo**B||     . o . o.o.B.||      = +   . . .||     . + o       ||        S .      ||         .       ||                 ||                 ||                 |+-----------------+

Then we created a public key pair in the. Ssh directory under our home directory.
We can see that

Cedric Porter@CedricPorter-PC ~/.ssh$ lsid_rsa  id_rsa.pub  known_hosts

Id_rsa is our key and id_rsa.pub is our public key. We write the public key to authorized_keys in the. Ssh directory of the server.

Cedric Porter@CedricPorter-PC ~/.ssh$ scp ~/.ssh/id_rsa.pub root@everet.org:~/.ssh/authorized_keys

In the future, we do not need to enter the password for both SSH and SCP.

Ssh-l root everet.org is required every time!

We can use aliases. For example, we can write alias ET = 'ssh-l root everet.org 'to. bashrc in the home directory and use aliases. You can also write the logon command to a file in the environment variable path, for example, to/usr/bin.

$ Echo "alias ET = 'ssh-l root everet.org '"> ~ /. Bashrc $ # Or run the following command $ echo "ssh-l root everet.org">/usr/bin/et $ chmod + x/usr/bin/et $ #. use et to log on to Cedric Porter @ cedricporter-PC ~ $ Etlinux localhost. localdomain 2.6.33.4-95. fc13.i686. PAE #1 SMP Thu May 13 05:38:26 UTC 2010 i686 GNU/linuxubuntu 10.10 welcome to Ubuntu! * Documentation: https://help.ubuntu.com/Last login: Fri Jan 20 10:55:50 2012 from 123.65.146.220root @ localhost :~ #
Disconnected, lost previous work !? Use screen to solve SSH Reconnection

# Screen-ls

You can view the current screen. If you cannot find the command, you can use apt-Get install screen. For more details, see the tutorial on the IBM website.

Http://www.ibm.com/developerworks/cn/linux/l-cn-screen/

After logging on, we can use screen-S et to create a new screen. When we are disconnected, we can reconnect to use screen-R et to restore the previous session. This is good. When we need to disconnect to go to bed, we can continue our work. When necessary, we should use screen to manage our sessions.

Synchronize data with the server

For data synchronization, it is found that rsync is quite good. Rsync was written by Andrew trigdell and Paul macherras. The idea is similar to rdist, but the focus is different. Rsync is a bit like an enhanced version of RCP. You can save permissions and other information during synchronization, and you can also perform incremental replication.

Next we will discuss how to enable rsync In ubuntu.

  1. Modify/etc/default/rsync to enable it to start automatically at startup. Change rsync_enable = false to rsync_enable = true.
  2. Set rsync. The configuration file is in/etc/rsyncd. conf. If it does not exist, create one. For example, create a configuration file VI/etc/rsyncd. conf.
  3. Enter the following content

[Et_wordpress]
Path =/var/www/ET
Secrets file =/etc/rsyncd. Secrets
Read Only = false
Uid = root
Gid = root

Close the work! Restart the daemon that enables rsync and enter/etc/init. d/rsync start. OK!

Now Let's synchronize data.

Download the server data back. I am now using cygwin on Windows. For example, if I synchronize my WordPress files back, you can use the following command:

Rsync-vzrtopg -- delete -- Progress everet.org: et_wordpress/cygdrive/h/coding/Everet/ET

When I modify a file locally, I can push my file to the server:

Rsync-vzrtopg -- delete -- Progress/cygdrive/h/coding/Everet/ET/* everet.org: et_wordpress

It is troublesome to input a long string of commands every time? For more information, see the abbreviated command for the second title above.

Echo "rsync-vzrtopg -- delete -- Progress everet.org: et_wordpress/cygdrive/h/coding/Everet/ET">/usr/bin/rcet
Echo "rsync-vzrtopg -- delete -- Progress/cygdrive/h/coding/Everet/ET/* everet.org: et_wordpress">/usr/bin/rcet2

Then we can use rcet to download server data and use rcet2 to push local data to the server.

In cygwin, the owner of each file that is pushed to the server changes, so we still need to modify the owner after the push, which will appear in cygwin, I don't know if it will happen in Linux, but it should not. If the file owner changes, you can modify the file owner after the push.

Ssh-l root everet.org "chown www-data: www-data-r/var/www/ET"

Well, we can add it to the alias of our push data. Modify the/usr/bin/rcet2 file:

Rsync-vzrtopg -- delete -- Progress/cygdrive/h/coding/Everet/ET/* everet.org: et_wordpress
Ssh-l root everet.org "chown www-data: www-data-r/var/www/ET"
Echo "done ."

We can easily push data.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.