Win7中用secureCRT连接虚拟机中的CentOS

    Win7中虚拟机里的Linux系统是装好了,root密码也改好了,却发现用CRT连接访问时怎么也访问不了。没办法又得网查找资料,可却发现网上的操作步骤很零散。经屡次尝试成功连接好之后,将操作步骤归纳如下:

一、虚拟机的网络连接设置:

1、将虚拟机的网络连接方式设置为bridge。

2、关闭CentOS的防火墙,可直接用root权限通过setup命令进行操作。

3、设置CentOS的ip为静态地址,不允许自动获取,这样远程连接不需要总修改地址。由于我是本机访问虚拟机,所以IP地址、子网掩码、DNS参考的是本机的配置。

 

二、配置ssh服务并使服务生效

1、修改/etc/ssh/sshd_config文件:

[root@qstarlx /]# vi /etc/ssh/sshd_config  ← 用vi打开SSH的配置文件

#Protocol 2,1 ← 找到此行将行头“#”删除,再将行末的“,1”删除,只允许SSH2方式的连接
 ↓
Protocol 2 ← 修改后变为此状态,仅使用SSH2

#ServerKeyBits 768 ← 找到这一行,将行首的“#”去掉,并将768改为1024
 ↓
ServerKeyBits 1024 ← 修改后变为此状态,将ServerKey强度改为1024比特

#PermitRootLogin yes  ← 找到这一行,将行首的“#”去掉,并将yes改为no
 ↓
PermitRootLogin no  ← 修改后变为此状态,不允许用root进行登录

#PasswordAuthentication yes ← 找到这一行,将yes改为no
 ↓
PasswordAuthentication no ← 修改后变为此状态,不允许密码方式的登录

#PermitEmptyPasswords no  ← 找到此行将行头的“#”删除,不允许空密码登录
 ↓
PermitEmptyPasswords no  ← 修改后变为此状态,禁止空密码进行登录

保存退出!

注:以上所改内容根据自己实际情况操作(去掉"#"表示启用,yes:允许;no:不允许)

2、重新启动ssh服务(注:这里要使用绝对路径):
[root@qstarlx /]# /etc/rc.d/init.d/sshd restart  ← 重新启动SSH服务器
Stopping sshd:             [ OK ]
Starting sshd:              [ OK ]  ← SSH服务器重新启动成功

 

三、开启linux centos的22、3306、80端口:

1、设定
[root@qstarlx ~]# /sbin/iptables -I INPUT -p tcp --dport 80 -j ACCEPT
[root@qstarlx ~]# /sbin/iptables -I INPUT -p tcp --dport 22 -j ACCEPT
[root@qstarlx ~]# /sbin/iptables -I INPUT -p tcp --dport 3306 -j ACCEPT

2、保存
[root@qstarlx ~]# /etc/rc.d/init.d/iptables save

3、重启防火墙
[root@qstarlx ~]# service iptables restart

4、查看
[root@qstarlx ~]# /etc/init.d/iptables status

 

 

四、SecureCRT使用PublicKey认证连接linux:

 

1、SecureCRT窗口->;Tools->;create public key...;或者Options->;Global options->;SSH2;点击"Create Identity File"
根据屏幕指示,创建你的key file.
选择密钥类型时,选择 RSA 方式,然后还会让你输入一个保护本地privatekey file的密码.生成key后,为生成的密钥选择一个文件名和存放的路径(可以自行修改或使用默认值).这个时候在指定目录会生成两个文件,例如私钥Identity和公钥Identity.pub

 

Server配置 

 

    把之前生成的后缀名为.pub的密钥文件传到 linux 服务器,将SSH2兼容格式的公钥转换成Openssh的兼容格式

 

# ssh-keygen -i -f Identity.pub >> /root/.ssh/authorized_keys

 


如果没有.ssh目录,先新建个
# mkdir /root/.ssh
# chmod 700 /root/.ssh
检查sshd服务的Pubkey认证功能是否默认打开
/etc/ssh/sshd_config:
PubkeyAuthentication yes /*开启pubkey认证
RSAAuthentication yes /*启用 RSA 认证
PasswordAuthentication no /*如果要禁止密码验证登录,这项就改为no
然后重启sshd服务
#service sshd restart或者/etc/init.d/sshd restart

 

posted @ 2012-06-10 12:33  跳动的音符^Web  阅读(1646)  评论(0编辑  收藏  举报