bin^2

bin^2

discord server
twitter

The SSH commands I often use.

SSH Commands I Often Use#

This article is generated using OpenCat + ChatGPT.

SSH is a commonly used network protocol that allows you to connect to remote servers, execute commands, transfer files, and more. Here are the SSH commands I often use:

1. Remote Port Forwarding#

Remote port forwarding allows you to forward a specific port on a remote server to a local port, allowing your local computer to access applications on the remote server, improving access speed and security.

ssh -f -N -R remote_port:local_ip:local_port user@remote_server

In this command, remote_port is the port to be forwarded on the remote server, local_ip and local_port are the IP address and port on your local computer, user is the username of the remote server, and remote_server is the address of the remote server.

2. Local Port Forwarding#

Local port forwarding allows you to forward a specific port on your local computer to a remote server, allowing the remote server to access applications on your local computer, improving access speed and security.

ssh -f -N -L local_port:remote_ip:remote_port user@remote_server

In this command, local_port is the port to be forwarded on your local computer, remote_ip and remote_port are the IP address and port on the remote server, user is the username of the remote server, and remote_server is the address of the remote server.

3. Proxy#

Proxy allows you to connect to a remote server via SSH and forward traffic to your local computer, enabling access to remote websites, improving access speed and security.

ssh -D local_port user@remote_server

In this command, local_port is the port on your local computer, user is the username of the remote server, and remote_server is the address of the remote server.

4. Copy File to Local#

You can copy files from a remote server to your local computer.

scp user@remote_server:/path/to/remote/file /path/to/local/file

In this command, user is the username of the remote server, remote_server is the address of the remote server, /path/to/remote/file is the file path on the remote server, and /path/to/local/file is the file path on your local computer.

5. Copy File to Remote#

You can copy files from your local computer to a remote server.

scp /path/to/local/file user@remote_server:/path/to/remote/file

In this command, /path/to/local/file is the file path on your local computer, user is the username of the remote server, remote_server is the address of the remote server, and /path/to/remote/file is the file path on the remote server.

6. Copy File from Remote to Remote via Local#

You can copy files from remote server 1 to remote server 2 via your local computer.

scp user1@remote_server1:/path/to/remote/file user2@remote_server2:/path/to/remote/file

In this command, user1 is the username of remote server 1, remote_server1 is the address of remote server 1, /path/to/remote/file is the file path on remote server 1, user2 is the username of remote server 2, remote_server2 is the address of remote server 2, and /path/to/remote/file is the file path on remote server 2.

7. Copy File from Remote to Remote, Peer-to-Peer#

You can directly copy files from remote server 1 to remote server 2, achieving peer-to-peer copying.

scp -3 user1@remote_server1:/path/to/remote/file user2@remote_server2:/path/to/remote/file

In this command, user1 is the username of remote server 1, remote_server1 is the address of remote server 1, /path/to/remote/file is the file path on remote server 1, user2 is the username of remote server 2, remote_server2 is the address of remote server 2, and /path/to/remote/file is the file path on remote server 2.

In conclusion, using SSH commands allows for easy connection to remote servers, execution of commands, file transfers, and more, improving work efficiency and security.

More#

View more SSH-related articles on xlog
View more SCP-related articles on xlog

Loading...
Ownership of this post data is guaranteed by blockchain and smart contracts to the creator alone.