A is A local host (that is, the machine used to control other hosts); B is A remote host (that is, the Server of the controlled machine), if the ip address is 172.24.253.2; both A and B are Linux commands on A: # ssh-keygen-trsa (press enter three times in A row, that is, A public key and private key are generated in the KeyStore...
A is A local host (that is, the machine used to control other hosts); B is A remote host (that is, the Server of the controlled machine), if the ip address is 172.24.253.2; both A and B are Linux commands on A: # ssh-keygen-t rsa (press enter three times in A row, that is, A public key and private key are generated in the KeyStore without A password) # ssh root@172.24.253.2 "mkdir. ssh; chmod 0700. ssh "(enter the password. note. set the ssh permission to 700) # scp ~ /. The ssh/id_rsa.pub root@172.24.253.2 :. ssh/id_rsa.pub (password required) command on B: # touch/root /. ssh/authorized_keys (if this file already exists, skip this one) # chmod 600 ~ /. Ssh/authorized_keys (# Note ~ /. Change the ssh/authorized_keys permission to 600. This file is used to save the public key generated by the ssh client. you can modify the ssh server configuration file/etc/ssh/sshd_config of the server to specify other file names) # cat/root /. ssh/id_rsa.pub>/root /. ssh/authorized_keys (append the content of id_rsa.pub to authorized_keys, be sure not to use>; otherwise, the original content will be cleared, so that others cannot log on with the original key) back to machine: # ssh root@172.24.253.2 (no password, login successful) if you specify another file name when generating the key pair (or need to control N machines, then you will generate multiple-to-key ), you need to use the parameter-I to specify the private key file # ssh root@172.24.253.2-I/path/to/your_id_rsa www.2cto.com scp is the same, For example, scp-I/root/. ssh/id_rsa./xxx 192.168.102.158:/home/wwy/bak. by default, the ssh command will use ~ /. Ssh/id_rsa is used as the private key file to log on. if you need to connect to multiple servers and do not want to specify the private key file every time you use the ssh command, the global configuration file/etc/ssh/ssh_config (or local configuration file ~ /. Ssh/config. if the file does not exist, create one.) add the following configuration: IdentityFile/path/to/your_id_rsa. you can also specify a Host configuration for each server: Host 172.24.253.2 IdentityFile/path/to/your_id_rsa if the following error occurs during connection: agent admitted failure to sign using the key, then use the ssh-add command? Debit? Jia ?? (Change id_rsa according to the individual's key name) 1ssh-add ~ /. Ssh/id_rsa: If you can protect your private key, enter the password on the shell, to ensure security, www.2cto.com #################################### ##################################### go deeper: first, the ssh-keygen-t rsa command generates a key and a public key, in addition, you can set your own password to understand the key as a key. The public key is understood as the lock header corresponding to the key, and the lock header (public key) is placed on the server to be controlled to lock the server, only persons with a key can open the lock header, enter the server, and control the key. for those who have the key, they must know the password of the key, this key can only be used (unless the key is not set with a password), so that the key can be prevented from being configured (the private key is copied). of course, this example is just easy to understand, with roo T-password users are certainly not locked, and not necessarily only have one lock (public key). However, if any lock is opened, it is opened with its corresponding key (private key, the server can be controlled by that person. Therefore, as long as you have known the root password of the server and put the public key with the root identity on it, you can use the private key corresponding to this public key to "open" server, and then log on as root, even if the root password has been changed! Method 2: install sshpass # sudo apt-get install sshpass. after the installation is complete, use sshpass to allow you to specify the plaintext password with the-p parameter, and then directly log on to the remote server. For example: # sshpass-p 'Your password 'Ssh username @ server IP address www.2cto.com after specifying the password with '-p', you also need to follow the standard ssh connection command. If the Sshd configuration file/etc/ssh/ssd_config require ssh has no password verification, send a command to the remote host: ssh username @ remote_server_ip your_command ssh username @ remote_server_ip "your_command1; your_command2; your_command3 "this article is from the fat shark network.
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