Vagrant更改默认的SSH端口
Vagrant默认转发宿主的2222端口到虚拟机的22端口(默认设置,无须配置)。在有多个虚拟机并存的情况下,2222端口将不好使。具体表现在:
- 启动第二个虚拟机的时候,会报端口占用错误:
$ vagrant up
Bringing machine 'default' up with 'virtualbox' provider...
Vagrant cannot forward the specified ports on this VM, since they would collide with some other application that is already listening on these ports. The forwarded port to 2222 is already in use on the host machine. To fix this, modify your current project's Vagrantfile to use another port. Example, where '1234' would be replaced by a unique host port:
config.vm.network :forwarded_port, guest: 22, host: 1234
Sometimes, Vagrant will attempt to auto-correct this for you. In this case, Vagrant was unable to. This is usually because the guest machine is in a state which doesn't allow modifying port forwarding. You could try 'vagrant reload' (equivalent of running a halt followed by an up) so vagrant can attempt to auto-correct this upon booting. Be warned that any unsaved work might be lost.
- 连接不同机器的SSH,会提示密钥不符:
$ ssh vagrant@localhost -p2222
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
@ 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 RSA key sent by the remote host is
SHA256:OmHXzdSe6B+pO6+xfvvFqKk40HAgzruemVeYbWYdF8c.
Please contact your system administrator. Add correct host key in /home/tlanyan/.ssh/known_hosts to get rid of this message. Offending ECDSA key in /home/tlanyan/.ssh/known_hosts:6 RSA host key for [localhost]:2222 has changed and you have requested strict checking.
Host key verification failed.
为了解决这个烦人的问题,只有为不同的虚拟机分配不同的主机端口。
根据提示,直接在Vagrantfile中更改转发端口:
config.vm.network "forwarded_port", guest: 22, host: 3333
然后启动机器,发现2222端口没有直接更改为3333,而是新增了3333端口:
$ vagrant reload
==> default: Attempting graceful shutdown of VM...
default: Guest communication could not be established! This is usually because
default: SSH is not running, the authentication information was changed,
default: or some other networking issue. Vagrant will force halt, if
default: capable.
==> default: Forcing shutdown of VM...
==> default: Clearing any previously set forwarded ports...
==> default: Clearing any previously set network interfaces...
==> default: Preparing network interfaces based on configuration...
default: Adapter 1: nat
==> default: Forwarding ports...
default: 22 (guest) => 3333 (host) (adapter 1)
default: 22 (guest) => 2222 (host) (adapter 1)
....
没办法,只好上网查查怎么回事。在官方的GitHub上,有相关 issue ,标题很有意思:“give a chance to disable default ssh port forwarding”。根据回复,解决办法是先禁用默认的ssh转发,再添加自定义转发:
config.vm.network "forwarded_port", guest: 22, host: 2222, id: "ssh", disabled: "true"
config.vm.network "forwarded_port", guest: 22, host: 3333
注意:第一条规则必须有 id: "ssh" ,否则会报如下错误:
Forwarded port ‘2222’ (host port) is declared multiple times with the protocol ‘tcp’.
重启后,即可看到转发端口已经更改为3333。
参考
- https://www.vagrantup.com/docs/vagrantfile/machine_settings.html
- https://github.com/mitchellh/vagrant/issues/1922
Vagrant更改默认的SSH端口的更多相关文章
- 阿里云修改默认的ssh端口
Linux服务器的ssh服务支持远程访问服务器,默认的ssh端口号是22.为了安全起见,很多用户会将端口号由22改为其他的端口号. 如果遇到修改端口号并重启ssh服务后,新的端口号不生效,请参考以下 ...
- 如何更改Linux的ssh端口
1. 修改/etc/ssh/sshd_config里的Port字段 Port 22改为Port 1000(你自定义的端口) 2. 重启sshd服务 #service sshd restart
- Ubuntu 16.04修改ssh端口
1 安装防火墙 sudo apt-get install ufw启用 sudo ufw enable sudo ufw default deny 作用:开启了防火墙并随系统启动同时关闭所有外部对本机的 ...
- Spring Boot - 修改Tomcat默认的8080端口
前言 默认情况下,Spring Boot内置的Tomcat服务会使用8080端口启动,我们可以使用以下任何技巧去更改默认的Tomcat端口: 注:我们可以通过server.port=0配置,去自动配置 ...
- 修改ssh端口
centos7.5修改默认SSH端口 linux SSH默认端口是22,不修改的话存在一定的风险,要么是被人恶意扫描,要么会被人破解或者攻击,所以我们需要修改默认的SSH端口 1.修改22端口为620 ...
- ssh更改默认端口号及实现免密码远程登陆
近来在复习防火墙管理工具 iptables 的基本使用方法,涉及到对端口添加或删除防火墙策略的内容,之前对ssh更改默认端口号及免密码登录的方法不熟悉,这次做一个基本的总结防止自己遗忘. 错误偏差及其 ...
- LINUX SSH修改默认22/添加端口
通常ssh远程登录的默认端口是22,但是因为端口22属于高危端口,因此很多时候作为服务器会被关掉,不过这个端口一般是可以更改或者添加的,这样除了22端口,也可以通过别的端口进行访问. 1.首先修改配置 ...
- webstorm 10 更改默认端口
快捷键 ctrl + Alt + s :打开配置 如图下可以更改 默认端口.快捷键可能跟qq的快捷键冲突,可以关闭qq来设置端口
- centos 7.0 修改ssh默认连接22端口 和 添加防火墙firewalld 通过端口
首先 先做的就是 修改ssh的默认端口22 需要修改文件 /etc/ssh/sshd_config 使用命令 vi /etc/ssh/sshd_config [root@localhost ~]# v ...
随机推荐
- golang的array/slice
相同点 由相同类型的元素组合构成 元素有序排列,0为第一个元素下标 基本使用方法相同 区别 array声明时需要指定容量大小,而且无法修改 slice可通过append增加元素,当容量不够时,会自动扩 ...
- Mysql事务及行级锁
事务隔离级别 数据库事务隔离级别,只是针对一个事务能不能读取其它事务的中间结果. Read Uncommitted (读取未提交内容) 在该隔离级别,所有事务都可以看到其他未提交事务的执行结果.本隔离 ...
- java 项目的jar 反编译后 压缩回去 命令
jar -cvfm0 123.jar META-INF\MANIFEST.MF(配置文件第一个位置) BOOT-INF org
- mysql 去重
select *, count(distinct name) from table group by name http://blog.sina.com.cn/s/blog_7e7249c301012 ...
- mysqldump test
CREATE TABLE IF NOT EXISTS `runoob_tbl`( `runoob_id` INT UNSIGNED AUTO_INCREMENT, `runoob_title` VAR ...
- windows下的phpunit安装
Windows Globally installing the PHAR involves the same procedure as manually installing Composer on ...
- centos 6.5使用virtualenv指定python 2.7.x
1. 使用现有的 python 2.6.x 安装pip rpm -ivh http://dl.fedoraproject.org/pub/epel/6/x86_64/epel-release-6-8. ...
- c/c++中关于String类型的思考
首先说明:String并不是一种内置类型,因此任何通过String声明出来的实例都不是一个变量,不同于内置类型因此String仅仅能称之为一种特殊的型别,没错String是一个类类型. 一般来说c语言 ...
- linux下安装或升级GCC4.8.2,以支持C++11标准[转]
在编译kenlm的时候需要安装gcc, 然后还需要安装g++. g++安装命令:sudo apt-get install g++ ----------------------以下为网上转载内容,加上自 ...
- CentOS 7 更换 阿里云/清华大学 yum 软件源
阿里云参考:https://opsx.alibaba.com/mirror?lang=zh-CN 清华参考:https://mirrors.tuna.tsinghua.edu.cn/help/cent ...