设为首页 收藏本站
查看: 1153|回复: 0

[经验分享] Linux 之 SSH 理解

[复制链接]

尚未签到

发表于 2019-2-18 07:29:32 | 显示全部楼层 |阅读模式
SSH 理解

一、服务端sshd_conf配置文件理解

Port 22                                                 #ssh 连接默认端口
PermitRootLogin yes                           #是否允许root用户登陆
PermitEmptyPasswords no                 #禁止空密码登陆
UserDNS no                                         #不使用DNS反解释
GSSAPIAuthentication no                    #禁用可加快初始连接的等待时间
ListenAddress  10.3.151.                      #只监控允许该网段的机器远程过来
#配置文件所在位置/etc/ssh/sshd_config
二、快速创建无密码远程登陆其它主机

1、主机环境

10.3.151.193  可直接控制访问10.3.151.222
2、在10.3.151.193上创建密钥对

[root@localhost ~]# ssh-keygen -t dsa
Generating public/private dsa key pair.
Enter file in which to save the key (/root/.ssh/id_dsa):
Enter passphrase (empty for no passphrase):
Enter same passphrase again:
Your identification has been saved in /root/.ssh/id_dsa.
Your public key has been saved in /root/.ssh/id_dsa.pub.
The key fingerprint is:
95:b4:14:45:60:9e:39:b2:89:02:d9:d4:55:3d:1f:80 root@localhost.localdomain
The key's randomart image is:
+--[ DSA 1024]----+
|    .. ...BB+.   |
|   +  .  =E=o .  |
|  o .   . O  o . |
|   .   . = .  .  |
|    . . S        |
|     .           |
|                 |
|                 |
|                 |
+-----------------+
备注:以下命令可直接快速创建密钥对
ssh-keygen -t dsa -P ' ' -f ~/.ssh/id_dsa > /dev/null 2>&1
[root@localhost ~]# ls -al .ssh/
总用量 20
drwx------.  2 root root 4096 6月   6 15:08 .
dr-xr-x---. 26 root root 4096 5月  27 15:25 ..
-rw-------   1 root root  668 6月   6 15:08 id_dsa                 #私钥
-rw-r--r--   1 root root  616 6月   6 15:08 id_dsa.pub           #公钥
-rw-r--r--   1 root root  786 5月  31 18:51 known_hosts
3、把公钥发送到要远程控制的主机

[root@localhost ~]# ssh-copy-id -i .ssh/id_dsa.pub  root@10.3.151.222
The authenticity of host '10.3.151.222 (10.3.151.222)' can't be established.
RSA key fingerprint is 55:5c:2f:0d:67:6d:b0:64:3e:7a:81:dd:54:9d:07:40.
Are you sure you want to continue connecting (yes/no)? yes
Warning: Permanently added '10.3.151.222' (RSA) to the list of known hosts.
root@10.3.151.222's password:
Now try logging into the machine, with "ssh 'root@10.3.151.222'", and check in:
.ssh/authorized_keys
to make sure we haven't added extra keys that you weren't expecting.
4、在被远程控制的机器上,查看.ssh下的文件

[root@localhost ~]# ls -al .ssh/
总用量 16
drwx------.  2 root root 4096 6月   6 15:11 .
dr-xr-x---. 24 root root 4096 5月  23 15:21 ..
-rw-------.  1 root root  616 6月   6 15:11 authorized_keys      #上传后生成的文件
-rw-r--r--.  1 root root  787 5月  23 13:05 known_hosts
5.测试10.3.151.193的机器是否可以直接访问10.3.151.222的机器(不需要密码)

[root@localhost ~]# ssh root@10.3.151.222 /sbin/ifconfig eth2
eth2      Link encap:Ethernet  HWaddr 00:50:56:B9:DA:C7  
inet addr:10.3.151.222  Bcast:10.3.151.255  Mask:255.255.255.0
inet6 addr: fe80::250:56ff:feb9:dac7/64 Scope:Link
UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
RX packets:667797 errors:0 dropped:0 overruns:0 frame:0
TX packets:206514 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:341023267 (325.2 MiB)  TX bytes:120677605 (115.0 MiB)



运维网声明 1、欢迎大家加入本站运维交流群:群②:261659950 群⑤:202807635 群⑦870801961 群⑧679858003
2、本站所有主题由该帖子作者发表,该帖子作者与运维网享有帖子相关版权
3、所有作品的著作权均归原作者享有,请您和我们一样尊重他人的著作权等合法权益。如果您对作品感到满意,请购买正版
4、禁止制作、复制、发布和传播具有反动、淫秽、色情、暴力、凶杀等内容的信息,一经发现立即删除。若您因此触犯法律,一切后果自负,我们对此不承担任何责任
5、所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其内容的准确性、可靠性、正当性、安全性、合法性等负责,亦不承担任何法律责任
6、所有作品仅供您个人学习、研究或欣赏,不得用于商业或者其他用途,否则,一切后果均由您自己承担,我们对此不承担任何法律责任
7、如涉及侵犯版权等问题,请您及时通知我们,我们将立即采取措施予以解决
8、联系人Email:admin@iyunv.com 网址:www.yunweiku.com

所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其承担任何法律责任,如涉及侵犯版权等问题,请您及时通知我们,我们将立即处理,联系人Email:kefu@iyunv.com,QQ:1061981298 本贴地址:https://www.yunweiku.com/thread-673703-1-1.html 上篇帖子: linux 常用的命令 下篇帖子: Linux nohup用法
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

扫码加入运维网微信交流群X

扫码加入运维网微信交流群

扫描二维码加入运维网微信交流群,最新一手资源尽在官方微信交流群!快快加入我们吧...

扫描微信二维码查看详情

客服E-mail:kefu@iyunv.com 客服QQ:1061981298


QQ群⑦:运维网交流群⑦ QQ群⑧:运维网交流群⑧ k8s群:运维网kubernetes交流群


提醒:禁止发布任何违反国家法律、法规的言论与图片等内容;本站内容均来自个人观点与网络等信息,非本站认同之观点.


本站大部分资源是网友从网上搜集分享而来,其版权均归原作者及其网站所有,我们尊重他人的合法权益,如有内容侵犯您的合法权益,请及时与我们联系进行核实删除!



合作伙伴: 青云cloud

快速回复 返回顶部 返回列表