25 SSH commands that must be remembered in Linux

Source: Internet
Author: User

25 SSH commands that must be remembered in Linux

1. Copy the SSH key to the target host and enable password-less SSH login.


If no key exists, use the ssh-keygen command to generate it.

2. Open a tunnel from port 80 of a host to port 2001 of the local host


Now you can enter http: // localhost: 2001 in your browser to access this website.

3. Output your microphone to a remote computer speaker


In this way, the sound from your microphone port will be output on the speaker port of the SSH target computer, but unfortunately, the sound quality is poor and you will hear a lot of hissing.

4. Compare remote and local files


This command is useful when comparing the differences between local and remote files.

5. Mount the directory/file system through SSH


Download sshfs from http://fuse.sourceforge.net/sshfs.htmlto allow you to upload a directory for cross-network security.

6. Establish an SSH connection through the intermediate host


Unreachable_host indicates that the host cannot be directly accessed from the local network, but can be accessed from the network where reachable_host is located. This command creates a connection to unreachable_host by "hiding" the connection to reachable_host.

7. Copy your SSH public key to a remote host and enable password-less logon.


8. directly connect to host A that can only be connected through host B


Of course, you must be able to access host.

9. Create a persistent connection to the target host


Create a persistent connection to the target host in the background and send this command to you ~ The configuration in/. ssh/config is used in combination:


All SSH connections to the target host will use persistent SSH sockets. If you use SSH to regularly synchronize files (using rsync/sftp/cvs/svn), this command will be very useful, because no new socket is created each time an SSH connection is opened.

10. Connect to the screen through SSH


Connect directly to a remote screen SESSION (saves useless parent bash processes ).

11. Port detection (knocking)


To open a service port (such as SSH) on a port, and then close the port, you need to install knockd first. The following is a configuration file example.


12. delete a line of content in a text file and fix it effectively.


In this case, it is best to use professional tools.

13. Run complex remote shell commands through SSH


More portable versions:


14. Copy the MySQL database to the new server through SSH


Dump a MySQL database through the compressed SSH tunnel and pass it as an input to the mysql command. I think this is the fastest and best way to migrate the database to the new server.

15. delete a row in the text file and fix the "SSH host key change" Warning.


16. Copy your SSH public key from a host without SSH-COPY-ID commands to the server


If you use Mac OS X or other * nix variants without the ssh-copy-id command, this command can copy your public key to a remote host, therefore, you can achieve SSH login without a password.

17. Real-time SSH network throughput Test


Connect to the host through SSH to display the real-time transmission speed. Point all transmitted data to/dev/null and install pv first.

For Debian:


If it is Fedora:


(Additional Software repositories may need to be enabled ).

18. If you create a remote GNU screen that can be reconnected


People always like to open many shells in a text terminal. If the session is suddenly interrupted or you press Ctrl-a d, the shell on the remote host will not be affected at all, you can reconnect. Other Useful screen Commands include "Ctrl-a c" (open a new shell) and "Ctrl-a" (switch back and forth between shells ), please visit http://aperiodic.net/screen/quick_referenceto read

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.