![ssh 服务器连接服务器](https://i-blog.csdnimg.cn/blog_migrate/fedebfc70d637581272310d385358d7a.png)
ssh 服务器连接服务器
![image image](https://i-blog.csdnimg.cn/blog_migrate/1da96b75fa4331d5d9c53af6b47ab746.png)
SSH offers more than just a secure, remote terminal environment. You can use SSH to tunnel your traffic, transfer files, mount remote file systems, and more. These tips and tricks will help you take advantage of your SSH server.
SSH不仅提供安全的远程终端环境。 您可以使用SSH来建立流量,传输文件,安装远程文件系统等。 这些提示和技巧将帮助您利用SSH服务器。
SSH doesn’t just authenticate over an encrypted connection – all your SSH traffic is encrypted. Whether you’re transferring a file, browsing the web, or running a command, your actions are private.
SSH不仅通过加密连接进行身份验证-您所有的SSH通信都已加密。 无论您是传输文件,浏览网页还是运行命令,操作都是私人的。
SSH隧道 (SSH Tunneling)
SSH tunneling allows a remote SSH server to function as a proxy server. Network traffic from your local system can be sent through the secure connection to the SSH server. For example, you could direct your web browsing traffic through an SSH tunnel to encrypt it. This would prevent people on public Wi-Fi networks from seeing what you’re browsing or bypass website and content filters on a local network.
SSH隧道允许远程SSH服务器充当代理服务器。 可以通过安全连接将来自本地系统的网络流量发送到SSH服务器。 例如,您可以通过SSH隧道引导Web浏览流量进行加密。 这样可以防止公共Wi-Fi网络上的人看到您正在浏览的内容,或者绕过本地网络上的网站和内容过滤器。
Of course, the traffic becomes unencrypted when it leaves the SSH server and accesses the Internet. To a web server you access through the tunnel, your connection will appear to be coming from the computer running your SSH server, not the local system.
当然,当流量离开SSH服务器并访问Internet时,流量将变得未加密。 对于通过隧道访问的Web服务器,您的连接似乎来自运行SSH服务器的计算机,而不是本地系统。
On Linux, use the following command to create a SOCKS proxy at port 9999 on your local system:
在Linux上,使用以下命令在本地系统上的端口9999上创建SOCKS代理:
ssh -D 9999 -C user@host
ssh -D 9999 -C user @ host
![image image](https://i-blog.csdnimg.cn/blog_migrate/a858f667e03c4832ff3475f5e32f874a.png)
‘
'
The tunnel will be open until your SSH connection terminates.
隧道将一直打开,直到您的SSH连接终止。
Open your web browser (or other application) and set the SOCKS proxy to port 9999 and localhost. Use localhost because the tunnel entrance is running on your local system.
打开您的Web浏览器(或其他应用程序),并将SOCKS代理设置为端口9999和localhost。 使用本地主机,因为隧道入口在本地系统上运行。
![image image](https://i-blog.csdnimg.cn/blog_migrate/ec83896ebc8599dd0a299726c80cfc6e.png)
We’ve also covered using PuTTY to set up an SSH tunnel on Windows.
我们还介绍了使用PuTTY在Windows上设置SSH隧道 。
SCP文件传输 (SCP File Transfers)
The scp, or secure copy, command allows you to transfer files between a remote system running an SSH server and your local system.
使用scp(或安全副本)命令可以在运行SSH服务器的远程系统和本地系统之间传输文件。
For example, to copy a local file to a remote system, use the following syntax:
例如,要将本地文件复制到远程系统,请使用以下语法:
scp /path/to/local/file user@host:/path/to/destination/file
scp /路径/到/本地/文件user @ host:/路径/到/目的地/文件
![image image](https://i-blog.csdnimg.cn/blog_migrate/adca009d19061d3fb727f15d2eef24ba.png)
To copy a file on a remote SSH server to the local system, use this syntax instead:
要将远程SSH服务器上的文件复制到本地系统,请改用以下语法:
scp -r user@host:/path/to/remote/file /path/to/destination/file
scp -r user @ host:/路径/到/远程/文件/路径/到/目的地/文件
You can also set up passwordless scp access and use scp to transfer files from within scripts.
您还可以设置无密码的scp访问,并使用scp从脚本内传输文件。
挂载远程目录 (Mounting Remote Directories)
You can mount a remote folder over SSH and access it like any other directory on your system, skipping the tedious scp process for file transfers.
您可以通过SSH挂载远程文件夹,并像系统上的任何其他目录一样访问它,而跳过繁琐的scp进程进行文件传输。
If you’re using Ubuntu or another GNOME-based desktop environment with the Nautilus file manager, launch the file manager, click the File menu and select Connect to Server.
如果您通过Nautilus文件管理器使用Ubuntu或其他基于GNOME的桌面环境,请启动文件管理器,单击“文件”菜单,然后选择“ 连接到服务器” 。
![image image](https://i-blog.csdnimg.cn/blog_migrate/39a2fa2d9d54cd157b203e62ae4fe386.png)
You’ll be prompted to enter the SSH server’s details and your credentials.
系统将提示您输入SSH服务器的详细信息和您的凭据。
![image image](https://i-blog.csdnimg.cn/blog_migrate/a8df21c61781884d68e43fc22970a751.png)
The files on the remote system will appear in your file manager.
远程系统上的文件将出现在文件管理器中。
![image image](https://i-blog.csdnimg.cn/blog_migrate/33e50f7d37c8bdd126f44791c425ca14.png)
Other Linux desktop environments may have similar options to easily mount a directory over SSH.
其他Linux桌面环境可能具有类似的选项,可以通过SSH轻松挂载目录。
If you don’t have access to a GUI or would rather use a terminal utility, you can use sshfs to mount the remote SSH system as a file system on your computer.
如果您无权访问GUI或希望使用终端实用程序,则可以使用sshfs将远程SSH系统挂载为计算机上的文件系统。
保留终端会话 (Preserving Terminal Sessions)
Every time you log in with SSH, you’ll be presented with a new terminal session. When you log out, your session will be closed. If you’d rather preserve a terminal session between SSH sessions, use GNU Screen or an alternative utility.
每次使用SSH登录时,都会看到一个新的终端会话。 当您注销时,您的会话将关闭。 如果您希望保留SSH会话之间的终端会话,请使用GNU Screen或其他实用程序 。
After logging into the remote system, run the screen command to launch a screen session. Run commands within the screen session, and then press Ctrl-a and then d to detach from the screen session.
登录到远程系统后,运行screen命令以启动屏幕会话。 在屏幕会话中运行命令,然后按Ctrl-a ,然后按d,以脱离屏幕会话。
The screen session and the commands running inside it continue to run in the background. To reattach to the screen session later, run the screen -r command.
屏幕会话及其内部运行的命令继续在后台运行。 要在以后重新连接到屏幕会话,请运行screen -r命令。
SSH can accept commands to run when you log in, so you can connect to an SSH server and reconnect to a screen session with a single command:
SSH可以接受登录时运行的命令,因此您可以使用一个命令连接到SSH服务器并重新连接到屏幕会话:
ssh -t user@host screen -r
ssh -t user @ host屏幕-r
![image image](https://i-blog.csdnimg.cn/blog_migrate/4360a5b8bcc3f864b6e18fc48724b222.png)
If you have local access to the system running the SSH server, you can move between accessing the screen session locally and remotely.
如果您对运行SSH服务器的系统具有本地访问权限,则可以在本地和远程访问屏幕会话之间切换。
可视化关键指纹 (Visualizing Key Fingerprints)
When you connect to your SSH server from another system, you’ll see a warning message if the system doesn’t already know its key. This message helps you ensure the remote system isn’t being impersonated by another system.
当您从另一个系统连接到SSH服务器时,如果系统尚不知道其密钥,则会看到警告消息。 此消息可帮助您确保远程系统不会被其他系统模仿。
![image image](https://i-blog.csdnimg.cn/blog_migrate/7d10cb36bdf37bfc0302b661cc34445b.png)
However, you may have trouble remembering the long string that identifies the remote system’s public key. To make the key’s fingerprint easier to remember, enable the “visual host key” feature.
但是,您可能难以记住用于标识远程系统公钥的长字符串。 为了使钥匙的指纹更容易记住,请启用“可视主机钥匙”功能。
You can enable this in your SSH config file or just specify it as an option while running the SSH command. For example, run the following command to connect to an SSH server with VisualHostKey enabled:
您可以在SSH配置文件中启用此功能,也可以在运行SSH命令时将其指定为选项。 例如,运行以下命令以连接到启用了VisualHostKey的SSH服务器:
ssh -o VisualHostKey=yes user@host
ssh -o VisualHostKey =是user @ host
![image image](https://i-blog.csdnimg.cn/blog_migrate/acc30544278435322e60449843e95f5e.png)
Now you’ll only have to remember the picture, not a long string.
现在,您只需要记住图片,而不必记住很长的字符串。
Do you have any other tips to share? Leave a comment and let us know.
您还有其他提示要分享吗? 发表评论,让我们知道。
翻译自: https://www.howtogeek.com/114812/5-cool-things-you-can-do-with-an-ssh-server/
ssh 服务器连接服务器