目录
Mac系统自带终端(terminal)和用于远程连接的ssh
客户端,因此连接Linux主机是非常方便的。本教程介绍如何连接到Linux主机执行各种shell命令,以及用scp
命令上传和下载文件。注意:如果你只是运行一键脚本而不手动编辑文件,无需关注上传和下载一节中的内容。
对于mac电脑用的比较多的网友,推荐使用iterm2
使用密码连接到Linux
1.打开“启动台” -> “其他”,点击“终端”(或者通过聚焦搜索spotlight输入terminal或终端打开),进入终端界面:
![terminal](https://xiaoheicn.top/wp-content/uploads/2022/09/终端启动界面.jpg)
2. 接着用ssh连接Linux主机,输入如下命令:ssh 用户名@ip -p端口号
,其中用户名一般是root,ip从服务器管理页面查看,端口号默认是22,搬瓦工的端口号请从后台查看。命里输完后按回车,首次连接会有主机指纹确认,输入yes后回车:
![](https://xiaoheicn.top/wp-content/uploads/2022/09/ssh连接确认.jpg)
接着提示输入密码,请复制管理页面上的密码,按 command+v
粘贴(注意粘贴和输入密码都不会有显示,这是正常的),然后回车。信息正确的话会进入到Linux主机界面:
![](https://xiaoheicn.top/wp-content/uploads/2022/09/ssh连接成功.jpg)
如果提示密码错误,请检查密码是否多复制了空格,以及用户名是否为root。如果出现如下提示:
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
@ WARNING: REMOTE HOST IDENTIFICATION HAS CHANGED! @
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
IT IS POSSIBLE THAT SOMEONE IS DOING SOMETHING NASTY!
Someone could be eavesdropping on you right now (man-in-the-middle attack)!
It is also possible that a host key has just been changed.
The fingerprint for the ED25519 key sent by the remote host is
先执行 rm -rf ~/.ssh/known_hosts
,然后再尝试ssh连接。
连接成功后,在这个界面开始执行各种教程里的命令吧!如果使用过程中命令出错,或者不希望其执行,随时按 ctrl + c 停止!
使用密钥连接到Linux服务器
某些VPS商家,例如AWS、Google、DMIT等,默认禁用了密码登录,此时需要使用密钥登录到服务器。
密钥登录的基本流程与密码登录基本一致,只在第二步有区别:密钥登录需要-i
参数指定密钥文件:ssh 用户名@服务器IP -p22 -i 密钥文件路径
。例如购买DMIT的服务器,从后台下载密钥文件(private_key)后,连接操作为:ssh
用户名@服务器IP
-p22 -i ~/dmit/private_key/id_rsa.pem
密钥登录比密码登录更安全,实践中推荐使用该方式登录服务器。
上传和下载文件
如果你不熟悉vi/vim
等终端编辑器,可以用scp
命令将要编辑的文件下载到本地,编辑好后再上传上去即可。
下载文件:打开一个新的tab(按command+t
),输入这个命令:scp 用户名@ip:服务器文件路径 .
,用户名一般是root,ip替换成服务器的真实ip,服务器文件路径一般以/开头,注意最后的.
不能省略!
例如复制 ShadowsocksR/SSR一键脚本 的配置文件到本地:scp root@13.26.3.2:/etc/shadowsocksR.json .
,然后按回车,按提示输入密码便开始复制过程。期间会显示进度条,复制完后文件一般在用户主目录下,在“访达”中可以找到。文件一般使用“文本编辑.app”就可以。
![](https://xiaoheicn.top/wp-content/uploads/2022/09/scp下载文件.jpg)
上传文件:上传文件的操作类似,命令为:scp 本地文件路径 用户名@ip:服务端文件路径
。例如将编辑好的shadowsocksR.json文件放回到服务端:scp shadowsocksR.json root@13.6.356.2:/etc/shadowsocksR.json
,然后按回车,根据提示输入密码,文件就上传成功了。
本教程到此就结束了,如果还有问题,欢迎留言!
留言
Fantastic goods from you, man. I’ve understand your stuff previous to and you’re just extremely excellent. I really like what you’ve acquired here, certainly like what you are stating and the way in which you say it. You make it entertaining and you still care for to keep it wise. I cant wait to read much more from you. This is really a terrific web site.
After all, what a great site and informative posts, I will upload inbound link – bookmark this web site? Regards, Reader.
Wohh exactly what I was searching for, appreciate it for posting.
When I initially commented I clicked the “Notify me when new comments are added” checkbox and now each time a comment is added I get three emails with the same comment. Is there any way you can remove people from that service? Appreciate it!
I¦ll right away seize your rss feed as I can not to find your email subscription hyperlink or e-newsletter service. Do you’ve any? Please allow me realize in order that I may just subscribe. Thanks.
Loving the info on this web site, you have done outstanding job on the posts.
Heya this is somewhat of off topic but I was wanting to know if blogs use WYSIWYG editors or if you have to manually code with HTML. I’m starting a blog soon but have no coding know-how so I wanted to get advice from someone with experience. Any help would be enormously appreciated!
You completed various nice points there. I did a search on the issue and found most persons will go along with with your blog.
Hmm it appears like your site ate my first comment (it was extremely long) so I guess I’ll just sum it up what I had written and say, I’m thoroughly enjoying your blog. I as well am an aspiring blog writer but I’m still new to everything. Do you have any suggestions for inexperienced blog writers? I’d really appreciate it.