Xshell是Windows下一款功能很是強大的安全終端模擬軟件,支持Telnet、Rlogin、SSH、SFTP、Serial 等協議,能夠很是方便的對linux主機進行遠程管理。
php
一、OpenSSH更改默認端口
html
(1)、主配置文件:/etc/ssh/sshd_configlinux
[root@www ~]# vim /etc/ssh/sshd_config
port 22 # 改爲2222
(2)、從新啓動服務shell
systemctl restart sshd.service
(3)、查看端口vim
[root@abc ~]# ss -tnl State Recv-Q Send-Q Local Address:Port Peer Address:Port LISTEN 0 128 *:2222 *:* LISTEN 0 128 :::2222 :::*
(4)、登陸測試 安全
Connecting to 172.16.38.3:2222... Connection established. To escape to local shell, press 'Ctrl+Alt+]'. WARNING! The remote SSH server rejected X11 forwarding request. Last login: Thu Jan 21 21:37:57 2016 from 172.16.38.1 [root@abc ~]#
(5)、在已經登錄的其餘終端直接登陸到172.16.38.3bash
[root@lgq ~]# ssh -p 2222 172.16.38.3 root@172.16.38.3's password: Last login: Thu Jan 21 21:57:19 2016 from 172.16.38.3 [root@abc ~]#
二、scp複製(兩種)ssh
本地主機爲172.16.38.3 遠程主機爲172.16.38.4
ide
(1)、PULL-------從遠程主機上獲取資源,前提遠程主機的資源可讀 工具
[root@abc ~]# scp -r root@172.16.38.4:/var/www/* /root/ root@172.16.38.4's password: index.html 100% 72 0.1KB/s 00:00 index.php 100% 21 0.0KB/s 00:00 configure.sh 100% 49 0.1KB/s 00:00 [root@abc ~]# ll total 4 -rw-------. 1 root root 1084 Jan 20 04:22 anaconda-ks.cfg drwxr-xr-x 2 root root 6 Jan 21 22:05 cgi-bin #複製過來的 drwxr-xr-x 3 root root 52 Jan 21 22:05 html #複製過來的
(2)、PUSH-------從本地主機複製給遠程主機,前提遠程主機的目錄可寫
[root@abc ~]# scp anaconda-ks.cfg root@172.16.38.4:/tmp root@172.16.38.4's password: anaconda-ks.cfg 100% 1084 1.1KB/s 00:00 在172.16.38.4遠程主機的/tmp目錄查看 [root@lgq tmp]# ls anaconda-ks.cfg
三、基於密鑰認證的實現
四、要登陸的Linux主機中配置:
配置文件:/etc/ssh/sshd_config
# The default is to check both .ssh/authorized_keys and .ssh/authorized_keys2 # but this is overridden so installations will only check .ssh/authorized_keys AuthorizedKeysFile .ssh/authorized_keys
[root@lgq ~]# chmod 700 .ssh [root@lgq ~]# cd .ssh [root@lgq .ssh]# ls known_hosts [root@lgq .ssh]# vim authorized_keys
[root@lgq .ssh]# ll total 8 -rw-r--r--. 1 root root 381 Jan 21 22:55 authorized_keys -rw-r--r--. 1 root root 180 Jan 20 21:28 known_hosts [root@lgq .ssh]# chmod 600 authorized_keys [root@lgq .ssh]# ll total 8 -rw-------. 1 root root 381 Jan 21 22:55 authorized_keys -rw-r--r--. 1 root root 180 Jan 20 21:28 known_hosts
登陸成功
Connecting to 172.16.38.4:22... Connection established. To escape to local shell, press 'Ctrl+Alt+]'. WARNING! The remote SSH server rejected X11 forwarding request. Last login: Thu Jan 21 23:07:09 2016 from 172.16.38.1 [root@lgq ~]#