Tips for managing remote hosts

Source: Internet
Author: User
Tags free ssh

Article Source: http://www.everet.org/2012/01/management-remote-host/ 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.
[Plain] view plaincopy
$ Ssh-keygen
Generating 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-PC
The key's randomart image is:
+ -- [RSA 2048] ---- +
|... + OEo ** B |
|. 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 $ ls id_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.
[Plain] view plaincopy
$ Echo "alias et = 'ssh-l root everet.org '"> ~ /. Bashrc
$ # Or use the following command
$ Echo "ssh-l root everet.org">/usr/bin/et
$ Chmod + x/usr/bin/et
$
$ # You can use et to log on later
Cedric Porter @ CedricPorter-PC ~
$ Et
Linux localhost. localdomain 2.6.33.4-95. fc13.i686. PAE #1 SMP Thu May 13 05:38:26 UTC 2010 i686 GNU/Linux
Ubuntu 10.10
 
Welcome to Ubuntu!
* Documentation: https://help.ubuntu.com/
Last login: Fri Jan 20 10:55:50 2012 from 123.65.146.220
Root @ 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.
Modify/etc/default/rsync to enable it to start automatically at startup. Change RSYNC_ENABLE = false to RSYNC_ENABLE = true.
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.
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.


From a flower

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.