用SSH来远程管理计算机,就不用到计算机实际地点来回跑了
环境:服务器:CentOS6.6,客户机win8.1 putty
配置服务器:
1、检查SSHD是否安装(默认情况下是系统自带的),使用命令
rpm -qa |grep ssh
结果如下表示已经安装
[[email protected] ~]# rpm -qa |grep ssh libssh2-1.4.2-1.el6.i686 openssh-server-5.3p1-104.el6.i686 openssh-5.3p1-104.el6.i686 openssh-clients-5.3p1-104.el6.i686
如果未安装使用下面的命令安装
yum install openssh-server
2、启动SSH,使用如下命令重启
service sshd restart
结果如下
[[email protected] ~]# service sshd restart 停止 sshd: [确定] 正在启动 sshd: [确定]
3、查看22端口是否处于监听状态,使用命令
netstat -antp |grep sshd
结果如下:
[[email protected] ~]# netstat -antp |grep sshd tcp 0 0 0.0.0.0:22 0.0.0.0:* LISTEN 1332/sshd tcp 0 0 192.168.116.130:22 192.168.116.1:51202 ESTABLISHED 1271/sshd tcp 0 0 :::22 :::* LISTEN 1332/sshd
4、查看是否放行22端口(windows中称为允许22端口出站),使用命令
iptables -nL
结果如下
[[email protected] ~]# iptables -nL Chain INPUT (policy ACCEPT) target prot opt source destination ACCEPT all -- 0.0.0.0/0 0.0.0.0/0 state RELATED,ESTABLISHED ACCEPT icmp -- 0.0.0.0/0 0.0.0.0/0 ACCEPT all -- 0.0.0.0/0 0.0.0.0/0 ACCEPT tcp -- 0.0.0.0/0 0.0.0.0/0 state NEW tcp dpt:22 REJECT all -- 0.0.0.0/0 0.0.0.0/0 reject-with icmp-host-prohibited Chain FORWARD (policy ACCEPT) target prot opt source destination REJECT all -- 0.0.0.0/0 0.0.0.0/0 reject-with icmp-host-prohibited Chain OUTPUT (policy ACCEPT) target prot opt source destination
下面我们来设置客户端,笔者用的客户端为putty
1、首先我们需要获得服务器的IP地址,最简单的方法用下面这个命令
ifconfig
笔者得到的结果
[[email protected] ~]# ifconfig eth0 Link encap:Ethernet HWaddr 00:0C:29:64:F6:6A inet addr:192.168.116.130 Bcast:192.168.116.255 Mask:255.255.255.0 inet6 addr: fe80::20c:29ff:fe64:f66a/64 Scope:Link UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1 RX packets:1813 errors:0 dropped:0 overruns:0 frame:0 TX packets:208 errors:0 dropped:0 overruns:0 carrier:0 collisions:0 txqueuelen:1000 RX bytes:172124 (168.0 KiB) TX bytes:35245 (34.4 KiB) Interrupt:19 Base address:0x2000 lo Link encap:Local Loopback inet addr:127.0.0.1 Mask:255.0.0.0 inet6 addr: ::1/128 Scope:Host UP LOOPBACK RUNNING MTU:65536 Metric:1 RX packets:0 errors:0 dropped:0 overruns:0 frame:0 TX packets:0 errors:0 dropped:0 overruns:0 carrier:0 collisions:0 txqueuelen:0 RX bytes:0 (0.0 b) TX bytes:0 (0.0 b)
可以看到,笔者获得的IP地址为192.168.116.130
2、打开putty,输入以下参数:IP:192.168.116.130(上一步命令获得的IP)、端口号:22、登陆方式:SSH,点击open
在弹出的窗口中如果有证书的确认,先点确认,然后会弹出用户名密码认证的窗口,输入centos的用户名密码即可,注意密码是不回显的。
login as: root [email protected]192.168.116.130‘s password: Last login: Sat May 9 16:37:43 2015 from 192.168.116.1 [[email protected] ~]#
时间: 2024-10-28 15:19:06