标签:
服务端:linl_S IP:10.0.0.15
1 [root@linl_C ~]# ls /mnt/Packages/openssh* 2 /mnt/Packages/openssh-5.3p1-94.el6.x86_64.rpm /mnt/Packages/openssh-clients-5.3p1-94.el6.x86_64.rpm 3 /mnt/Packages/openssh-askpass-5.3p1-94.el6.x86_64.rpm /mnt/Packages/openssh-server-5.3p1-94.el6.x86_64.rpm
1 [root@linl_C ~]# rpm -qpi /mnt/Packages/openssh-server-5.3p1-94.el6.x86_64.rpm 2 warning: /mnt/Packages/openssh-server-5.3p1-94.el6.x86_64.rpm: Header V3 RSA/SHA256 Signature, key ID fd431d51: NOKEY 3 Name : openssh-server Relocations: (not relocatable) 4 Version : 5.3p1 Vendor: Red Hat, Inc. 5 Release : 94.el6 Build Date: Mon 30 Sep 2013 03:08:20 PM CST 6 Install Date: (not installed) Build Host: x86-022.build.eng.bos.redhat.com 7 Group : System Environment/Daemons Source RPM: openssh-5.3p1-94.el6.src.rpm 8 Size : 689757 License: BSD 9 Signature : RSA/8, Mon 28 Oct 2013 03:12:04 PM CST, Key ID 199e2f91fd431d51 10 Packager : Red Hat, Inc. <http://bugzilla.redhat.com/bugzilla> 11 URL : http://www.openssh.com/portable.html 12 Summary : An open source SSH server daemon 13 Description : 14 OpenSSH is a free version of SSH (Secure SHell), a program for logging 15 into and executing commands on a remote machine. This package contains 16 the secure shell daemon (sshd). The sshd daemon allows SSH clients to 17 securely connect to your SSH server.
1 [root@linl_C ~]# chkconfig sshd on | off 2 [root@linl_C ~]# chkconfig --list sshd 3 sshd 0:off 1:off 2:on 3:on 4:on 5:on 6:off
方法1:ssh [远程主机用户名]@[远程服务器主机名或IP地址]
1 [root@linl_C ~]# ssh 10.0.0.15 #如果用root进行登录远程主机可以省略用户名 2 The authenticity of host ‘10.0.0.15 (10.0.0.15)‘ can‘t be established. 3 RSA key fingerprint is e9:1f:3a:40:e9:79:a9:33:ff:b9:37:23:a6:1f:70:29. 4 Are you sure you want to continue connecting (yes/no)? yes #填入完整的“yes”,而不是Y或y而已 5 Warning: Permanently added ‘10.0.0.15‘ (RSA) to the list of known hosts. 6 root@10.0.0.15‘s password: 7 Last login: Thu May 19 11:25:32 2016 from 10.0.0.1 8 [root@linl_S ~]# #已经登录到lin_S端
1 [root@linl_C ~]# ssh -l root 10.0.0.15 #这里的用户名root不能省略 2 The authenticity of host ‘10.0.0.15 (10.0.0.15)‘ can‘t be established. 3 RSA key fingerprint is e9:1f:3a:40:e9:79:a9:33:ff:b9:37:23:a6:1f:70:29. 4 Are you sure you want to continue connecting (yes/no)? yes 5 Warning: Permanently added ‘10.0.0.15‘ (RSA) to the list of known hosts. 6 root@10.0.0.15‘s password: 7 Last login: Thu May 19 13:53:19 2016 from 10.0.0.1 8 [root@linl_S ~]# #已经登录到lin_S端
1 [root@linl_S ~]# useradd linypwb 2 [root@linl_S ~]# echo 123456 |passwd --stdin linypwb 3 Changing password for user linypwb. 4 passwd: all authentication tokens updated successfully.
1 [root@linl_C ~]# vi /etc/hosts 2 127.0.0.1 localhost localhost.localdomain localhost4 localhost4.localdomain4 3 ::1 localhost localhost.localdomain localhost6 localhost6.localdomain6 4 10.0.0.15 lin_S lin_S
1 [root@linl_C ~]# ssh linypwb@lin_S date 2 linypwb@lin_s‘s password: 3 Thu May 19 14:37:38 CST 2016 4 [root@linl_C ~]# #身份还是root,只是以linypwb的身份在远程主机上执行了一个命令而已
1 [root@linl_C ~]# vi .ssh/known_hosts 2 lin_s ssh-rsa AAAAB3NzaC1yc2EAAAABIwAAAQEAmdWhFkQGgpPhjELJnP5+G6OEJ5+dS3EbISKrctYbxd82USSnYyqiWcxOb7IpMoVltvyvciwf8/6B666fkNAW7WDR89afGL6yrwC8+PB3fwkSg9RPyZw4qGoEGoP/Z5LNa8MzYHf+98pzZ9VllmWUpDkP9lkhqeSMdIRxP5WyK9z1HRdE9N+KbIKjpJBvchchyaBYgwOWArF8Joyz0tyRpf48iXu5/8fizNNWnHNvC6IZDRqu8DdphGyAFPksW/1DXN5eSmMYbPo2R2OGEfEvdt3xSSsoK2Vws6osFma19E7tb2zd4BTmOYiLJtgmzVkGFdgk5a/q4jgWHTdi6C+wjw==
1 [root@linl_S ~]# cp /etc/ssh/sshd_config{,.bak} #修改配置文件前,尽量备份文件,以便出错能够及时恢复
1 [root@linl_S ~]# vi /etc/ssh/sshd_config
2 ...
3 #Port 22
4 Port 22 #监听端口22
5 Port 222 #监听端口222
6 #AddressFamily any
7 #ListenAddress 0.0.0.0
8 #ListenAddress ::
9 ...
10 [root@linl_S ~]# service sshd restart #重启sshd服务
11 Stopping sshd: [ OK ]
12 Starting sshd: [ OK ]
13 [root@linl_S ~]# netstat -anptu |grep ssh #查看sshd监听端口
14 tcp 0 0 0.0.0.0:22 0.0.0.0:* LISTEN 3549/sshd
15 tcp 0 0 0.0.0.0:222 0.0.0.0:* LISTEN 3549/sshd
16 tcp 0 52 10.0.0.15:22 10.0.0.1:57030 ESTABLISHED 2574/sshd
17 tcp 0 0 :::22 :::* LISTEN 3549/sshd
18 tcp 0 0 :::222 :::* LISTEN 3549/sshd
1 [root@linl_C ~]# ssh lin_S -p 222 #如果用root进行登录远程主机可以省略用户名 2 root@lin_s‘s password: 3 Last login: Thu May 19 14:31:03 2016 from 10.0.0.16 4 [root@linl_S ~]# #已经登录到lin_S端
1 [root@linl_S ~]# vi /etc/sysconfig/network-scripts/ifcfg-eth1 #编辑网卡信息,以下均为必要项 2 DEVICE=eth1 3 ONBOOT=yes 4 BOOTPROTO=static 5 IPADDR=10.0.0.14 6 PREFIX=24 7 GATEWAY=10.0.0.1 8 DNS1=8.8.8.8 9 NETMASK=255.255.255.0 10 [root@linl_S ~]# service network restart #重启网络服务 11 Shutting down interface eth0: [ OK ] 12 Shutting down loopback interface: [ OK ] 13 Bringing up loopback interface: [ OK ] 14 Bringing up interface eth0: Determining if ip address 10.0.0.15 is already in use for device eth0... 15 [ OK ] 16 Bringing up interface eth1: Determining if ip address 10.0.0.14 is already in use for device eth1... 17 [ OK ]
1 [root@linl_S ~]# vi /etc/ssh/sshd_config #修改监听IP 2 ... 3 #Port 22 4 #AddressFamily any 5 #ListenAddress 0.0.0.0 6 ListenAddress 10.0.0.14 7 #ListenAddress :: 8 ... 9 [root@linl_S ~]# service sshd restart #重启ssh服务 10 Stopping sshd: [ OK ] 11 Starting sshd: [ OK ] 12 [root@linl_S ~]# netstat -anptu |grep sshd #查看监听情况 13 tcp 0 0 10.0.0.14:22 0.0.0.0:* LISTEN 4284/sshd
1 [root@linl_C ~]# ssh lin_S 2 ssh: connect to host lin_S port 22: Connection refused #提示拒绝连接 3 [root@linl_C ~]# ssh 10.0.0.14 #连接监听IP则可以 4 The authenticity of host ‘10.0.0.14 (10.0.0.14)‘ can‘t be established. 5 RSA key fingerprint is e9:1f:3a:40:e9:79:a9:33:ff:b9:37:23:a6:1f:70:29. 6 Are you sure you want to continue connecting (yes/no)? yes 7 Warning: Permanently added ‘10.0.0.14‘ (RSA) to the list of known hosts. 8 root@10.0.0.17‘s password: 9 Last login: Thu May 19 16:18:50 2016 10 [root@linl_S ~]# #已经登录到lin_S
1 [root@linl_S ~]# vi /etc/ssh/sshd_config 2 #Protocol 2 3 Protocol 2,1
1 # HostKey for protocol version 1 2 #HostKey /etc/ssh/ssh_host_key #SSH v1使用的私钥 3 # HostKeys for protocol version 2 4 #HostKey /etc/ssh/ssh_host_rsa_key #SSH v2使用的RSA私钥 5 #HostKey /etc/ssh/ssh_host_dsa_key #SSH v2使用的DSA私钥
# 当有人使用 SSH 登入系统的时候,SSH 会记录信息,这个信息要记录的类型为AUTHPRIV。
1 [root@linl_S ~]# vim /etc/rsyslog.conf 2 # The authpriv file has restricted access. 3 authpriv.* /var/log/secure
1 #PermitRootLogin yes #是否允许root登入!预设是允许的,但是建议设定成no! 2 #PermitEmptyPasswords no #若上面那一项设定为yes的话,这一项就最好设定为no 这个项目在是否允许以空的密码登入!当然不允许! 3 #PasswordAuthentication yes #是否允许使用密码验证,默认为允许 4 #StrictModes yes #当使用者的 host key 改变之后,Server 就不接受联机,可以抵挡部分的木马程序! 5 #PubkeyAuthentication yes #是否允许Public Key?当然允许啦!仅针对version 2
# 当使用者连上 SSH server 之后,会出现输入密码的画面,在该画面中,
# 在多久时间内没有成功连上 SSH server 就强迫断线!若无单位则默认时间为秒!1 [root@lin_C ~]# ssh lin_S 2 root@lin_s‘s password: #停留5秒后,再次输入,结果断开 3 Connection closed by lin_S
1 [root@linl_S ~]# echo "欢迎登录本系统,所有操作都将有记录" > /etc/motd 2 [root@linl_C ~]# ssh lin_S #在lin_C 客户端测试访问lin_S 3 root@lin_s‘s password: 4 Last login: Thu May 19 17:59:06 2016 from 10.0.0.16 5 欢迎登录本系统,所有操作都将有记录 #打印出了/etc/motd 中的内容 6 [root@linl_S ~]#
# PrintLastLog yes
# 显示上次登入的信息!预设也是 yes!
Last login: Wed Mar 23 22:12:58 2016 from 192.168.1.100
#改:PrintLastLog yes 为:PrintLastLog no 就不显示这个信息
标签:
原文地址:http://www.cnblogs.com/linypwb/p/5567774.html