赞
踩
- [root@localhost ~]# vim /etc/ssh/sshd_config
-
- #Port 22
- #AddressFamily any
- #ListenAddress 0.0.0.0
- #ListenAddress ::
-
- HostKey /etc/ssh/ssh_host_rsa_key
- #HostKey /etc/ssh/ssh_host_dsa_key
- HostKey /etc/ssh/ssh_host_ecdsa_key
- HostKey /etc/ssh/ssh_host_ed25519_key
-
- # Ciphers and keying
- #RekeyLimit default none
-
- ......
-
注:telnet协议使用udp的23端口,明文传输数据;mstsc远程桌面功能使用3389端口(windows系统);VNC(跨系统远程连接);TeamVlewer(手机与PC端之间远程连接)
- PermitRootLogin no //禁止root用户远程登录
- PermitEmptyPasswords no //禁止空密码用户远程登录
- MaxAuthTries 6 //最大重试次数为6
- AllowUsers //白名单,仅允许用户远程登录
- DenyUsers //黑名单,仅拒绝用户远程登录
- 黑名单与白名单注意不要同时使用
- AllowUsers zhangsan root@192.168.43.132 //仅允许该IP地址的主机zhangsan,
- root账户登录,多个用户之间用空格隔开
- [root@day01 ~]# ssh root@192.168.43.132
- root@192.168.43.132's password:
- Last login: Sun Nov 24 20:57:36 2019 from 192.168.43.147
- [root@day02 ~]# exit
- 登出
- Connection to 192.168.43.132 closed.
- [root@day01 ~]#
-
- 在服务端设置禁止root用户被远程登录
- [root@day02 ~]# vim /etc/ssh/sshd_config
-
- PermitRootLogin no
-
- [root@day02 ~]# systemctl restart sshd //重启服务,更新参数
- [root@day02 ~]#
- 在客户端尝试登录root
- [root@day01 ~]# ssh root@192.168.43.132
- root@192.168.43.132's password:
- Permission denied, please try again.
- root@192.168.43.132's password:
- Permission denied, please try again.
- root@192.168.43.132's password:
- [root@day01 ~]# ssh zhangsan@192.168.43.132 //登录服务端的zhangsan用户
- zhangsan@192.168.43.132's password:
- Last login: Thu Oct 31 11:10:07 2019
- [zhangsan@day02 ~]$ su - root //使用su命令切换
- 密码:
- [root@day02 ~]# vim /etc/pam.d/su //开启PAM认证,限制su命令的切换
-
- auth required pam_wheel.so use_uid
-
-
-
- [root@day01 .ssh]# ssh-keygen -t rsa
- Generating public/private rsa key pair.
- Enter file in which to save the key (/root/.ssh/id_rsa): //密钥对的路径
- Enter passphrase (empty for no passphrase): //输入密钥
- Enter same passphrase again:
- Your identification has been saved in /root/.ssh/id_rsa.
- Your public key has been saved in /root/.ssh/id_rsa.pub.
- The key fingerprint is:
- SHA256:IkCe/o4389L3ZArgsUCdGYRlX+VBP8nocKPr6Okppas root@day01
- The key's randomart image is:
- +---[RSA 2048]----+
- | .+= .o+ |
- | o.+ = . . = . |
- | = + . . = = |
- | o . = . . |
- | o + . S . |
- | + =.. . |
- | ++. . o |
- | oB .*.+ |
- | EooXB.o.. |
- +----[SHA256]-----+
- [root@day01 .ssh]#
- //输入密钥时要有复杂度
- [root@day01 .ssh]# cd /root/.ssh
- [root@day01 .ssh]# ls
- id_rsa id_rsa.pub //id_rsa为私钥,id_rsa.pub为公钥
- [root@192 .ssh]# ssh-copy-id -i id_rsa.pub root@192.168.43.134
- /usr/bin/ssh-copy-id: INFO: Source of key(s) to be installed: "id_rsa.pub"
- /usr/bin/ssh-copy-id: INFO: attempting to log in with the new key(s), to filter out any that are already installed
- /usr/bin/ssh-copy-id: INFO: 1 key(s) remain to be installed -- if you are prompted now it is to install the new keys
- root@192.168.43.134's password:
- Number of key(s) added: 1
- Now try logging into the machine, with: "ssh 'root@192.168.43.134'"
- and check to make sure that only the key(s) you wanted were added.
- [root@192 .ssh]#
- [root@192 .ssh]# ssh-agent bash
- [root@192 .ssh]# ssh-add
- Enter passphrase for /root/.ssh/id_rsa:
- Identity added: /root/.ssh/id_rsa (/root/.ssh/id_rsa)
- [root@192 .ssh]#
- [root@192 .ssh]# ssh root@192.168.43.134
- Last login: Sun Nov 24 21:48:39 2019 from 192.168.43.148
- [root@demo ~]#
-
注:输入密钥是需要由复杂度,即不能单纯输入数字。但是也可以不输入密钥,这样也可以实现“免交互”
- [root@demo mnt]# ls
- a.txt
- [root@demo mnt]# cat a.txt
- hello world
-
- [root@demo mnt]# scp a.txt root@192.168.43.134:/mnt/a.txt
- root@192.168.43.134's password:
- a.txt 100% 13 7.1KB/s 00:00
- [root@demo mnt]# ls
- a.txt
- [root@demo mnt]# cat a.txt
- hello world
-
- [root@demo mnt]#
-
- [root@demo mnt]# ls
- a.txt b.txt
- [root@demo mnt]# cat a.txt
- [root@demo mnt]# cat b.txt
- 123
- [root@demo mnt]# cat a.txt
- hello world
-
- [root@demo mnt]#
-
- [root@demo mnt]# scp root@192.168.43.134:/mnt/c.txt ./
- root@192.168.43.134's password:
- c.txt 100% 3 2.7KB/s 00:00
- [root@demo mnt]# ls
- a.txt c.txt
- [root@demo mnt]# cat c.txt
- zz
- [root@demo mnt]#
-
- [root@demo mnt]# vim c.txt
- [root@demo mnt]# ls
- a.txt c.txt
- [root@demo mnt]# cat c.txt
- zz
- [root@demo mnt]#
- [root@192 mnt]# ls
- d.txt
- [root@192 mnt]# sftp root@192.168.43.134
- sign_and_send_pubkey: signing failed: agent refused operation
- root@192.168.43.134's password:
- Connected to 192.168.43.134.
- sftp> ls
- anaconda-ks.cfg initial-setup-ks.cfg 下载 公共
- 图片 文档 桌面 模板
- 视频 音乐
- sftp> cd /mnt
- sftp> ls
- a.txt c.txt
- sftp> get a.txt /mnt
- Fetching /mnt/a.txt to /mnt/a.txt
- /mnt/a.txt 100% 13 2.2KB/s 00:00
- sftp> put /mnt/d.txt /mnt
- Uploading /mnt/d.txt to /mnt/d.txt
- /mnt/d.txt 100% 8 1.9KB/s 00:00
- sftp> exit
- [root@192 mnt]# ls
- a.txt d.txt
- [root@192 mnt]#
- [root@demo mnt]# ls
- a.txt c.txt
- [root@demo mnt]# ls
- a.txt c.txt d.txt
- [root@demo mnt]#
-
- [root@192 ~]# vim /etc/hosts.allow
-
- #
- # hosts.allow This file contains access rules which are used to
- # allow or deny connections to network services that
- # either use the tcp_wrappers library or that have been
- # started through a tcp_wrappers-enabled xinetd.
- #
- # See 'man 5 hosts_options' and 'man 5 hosts_access'
- # for information on rule syntax.
- # See 'man tcpd' for information on tcp_wrappers
- #
- [root@192 ~]# vim /etc/hosts.deny
- #
- # hosts.deny This file contains access rules which are used to
- # deny connections to network services that either use
- # the tcp_wrappers library or that have been
- # started through a tcp_wrappers-enabled xinetd.
- #
- # The rules in this file can also be set up in
- # /etc/hosts.allow with a 'deny' option instead.
- #
- # See 'man 5 hosts_options' and 'man 5 hosts_access'
- # for information on rule syntax.
- # See 'man tcpd' for information on tcp_wrappers
- #
注:在这两个配置文件中可以使用通配符*和?;ALL代表所有,如sshd:ALL,即拒绝或者允许所有用户拒绝访问或者访问ssh服务;“,”代表间隔,如两个IP地址之间,两个服务之间可以用“,”隔开。
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。