Summary of linux Command ssh, linux Command ssh
Because the project requires a large amount of computing, You need to distribute tasks to multiple computers for running. Because you are not familiar with the distributed concept, you can think of the simplest ssh protocol in linux to remotely control other computers, then write a shell script to run the program on all computers. (my operating system is Ubuntu16.04)
First, run the following command on your computer to check whether ssh is installed.
Ps-e | grep ssh
If the returned result is sshd in, it indicates that ssh has been installed. Otherwise, the installation is online.
Sudo apt-get install ssh installation.
Next, when we use ssh to log on to another computer, ssh username @ ip will be logged on, and a prompt will be prompted to enter the password. At this time, enter the password to remotely control another computer.
(Ifconfig view ip address)
If you have ten computers that require you to connect to and assign tasks, you must remember the ip address and password of the computer every time. This is not conducive to the unified running of scripts, therefore, the first step is to allow password-free logon from a computer that requires remote control.
First, we generate a key on your computer.
Ssh-keygen, and enter all the way. The. ssh folder is generated in the main directory.
Ls-a (check whether the. ssh folder is generated)
Go to the. ssh folder and view the file.
The key pair has been generated. Next, copy the public key to the computer you want to connect to through scp.
Cat ~ /. Ssh/id_rsa.pub> ~ /. Ssh/authorized_keys
Scp ~ /. Ssh/id_rsa.pub username @ ip :~ /. Ssh/id_rsa.pub_copy
Next, remotely connect to the computer you need to connect as the server
Touch ~ /. Ssh/authorized_keys
Cat ~ /. Ssh/id_rsa.pub_copy> ~ /. Ssh/authorized_keys
At this time, the last step is to modify the permissions.
Chmod 755 ~
Chmod 700 ~ /. Ssh
Chmod 600 ~ /. Ssh/authorized_keys
Many people do not understand the meaning of the 755,700,600 data. This is a digital expression of linux permissions.
For example, when we view the permission of a file
We will see the above results. The previous part is composed of ten digits in the form of 1-3-3. The first letter indicates the file type, and d indicates the first letter of the document folder, the first three digits indicate the permissions of the owner, the second three digits indicate the permissions of the group, and the third three digits indicate the permissions of other groups. R -- read, W-write, and X-Execute. Therefore, rwx indicates that the current group is readable and writable. return to the preceding number. R corresponds to numbers 4, W corresponds to 2, and X corresponds to 1. now we can understand that 755 indicates that the owner is readable and writable, and the group is writable and executable. Other groups are also writable and executable.
Now, you can test whether you can log on to another user's computer without a password.
During the running process, you may encounter this problem. This indicates that the ssh-agent is running, but the corresponding key is not found. We can solve this problem through ssh-add, you can also use ssh-add-l to view the attached key.
In the remote connection, you still need to enter the user name and ip address. If you do not want to enter the user name, you can create the same user for all the computers at first.
Script to run all programs
Screen-dm ssh-t username1 @ ip1 "..." (enter the command you want to run in the quotation marks)
Screen-dm ssh-t username2 @ ip2 "..."
Ps: I hope you can give me more advice on poor writing.