前言:
創(chuàng)新互聯(lián)網(wǎng)站建設(shè)提供從項(xiàng)目策劃、軟件開發(fā),軟件安全維護(hù)、網(wǎng)站優(yōu)化(SEO)、網(wǎng)站分析、效果評估等整套的建站服務(wù),主營業(yè)務(wù)為網(wǎng)站建設(shè)、成都網(wǎng)站建設(shè),APP應(yīng)用開發(fā)以傳統(tǒng)方式定制建設(shè)網(wǎng)站,并提供域名空間備案等一條龍服務(wù),秉承以專業(yè)、用心的態(tài)度為用戶提供真誠的服務(wù)。創(chuàng)新互聯(lián)深信只要達(dá)到每一位用戶的要求,就會(huì)得到認(rèn)可,從而選擇與我們長期合作。這樣,我們也可以走得更遠(yuǎn)!
SSH遠(yuǎn)程管理
1.配置OpenSSH服務(wù)端
2.使用SSH客戶端程序
3.密鑰對驗(yàn)證的SSH體系
TCP Wrappers概述 (針對程序的管理機(jī)制)
1.TCP Wrappers 概述
2.TCP Wrappers訪問策略
第二種遠(yuǎn)程訪問:telnet 也是遠(yuǎn)程訪問,是不會(huì)經(jīng)過加密的明文傳輸,可以用抓包工具直接獲取其中的消息 23 tcp 端口;而ssh 是典型的密文訪問
因此tlelent 主要應(yīng)用于局域網(wǎng);ssh皆可
第三種遠(yuǎn)程訪問是遠(yuǎn)程桌面,3389端口號(hào),帶有圖形化訪問
例:mstsc命令 windows 中的遠(yuǎn)程桌面訪問形式
通過遠(yuǎn)程訪問的用戶必須給其設(shè)置密碼
vnc軟件可以跨微軟系統(tǒng)和linux系統(tǒng)之間連接
teamviewer軟件 手機(jī)連接電腦
被遠(yuǎn)程方可以手動(dòng)關(guān)閉拒絕遠(yuǎn)程
ssh_config 是針對客戶端的
shhd_config是服務(wù)端
[root@localhost ~]# vim /etc/ssh/sshd_config
......
#Port 22 '端口號(hào)(可以修改)'
#ListenAddress 0.0.0.0 '監(jiān)聽地址'
Protocol 2 '版本'
#UseDNS no 'DNS反向解析 否'
AllowUsers 白名單 :僅允許登陸
DenyUsers 黑名單 :僅拒絕登陸
[root@localhost ~]# vim /etc/ssh/sshd_config
#LoginGraceTime 2m '登錄時(shí)間2min 超過2min自動(dòng)注銷'
#PermitRootLogin yes '允許root登陸 是 前面有#符號(hào)注釋則不可以使用'
#StrictModes yes '嚴(yán)格遵循標(biāo)準(zhǔn)模式 是'
#MaxAuthTries 6 '最大嘗試登陸次數(shù)為 6'
#MaxSessions 10 '最大創(chuàng)建會(huì)話為 10'
PermitEmptPasswords no '允許空密碼登陸 否'
······
AllowUsers jerry admin@61.23.24.25
'白名單,只允許以下用從指定終端登錄,用戶與用戶之間用空格隔開'
AllowUsers的權(quán)限比DenyUsers的權(quán)限大,AllowsUsers不要與DenyUsers同時(shí)用
密鑰對的方式需要自己去創(chuàng)建
密鑰對里面包含公鑰和私鑰,合在一起叫密鑰對
公鑰給對方,私鑰自己保留,這種方式叫做非對稱密鑰 rsa 相當(dāng)于虎符
des 或aex或3des模式 是對稱密鑰,相當(dāng)于門鑰匙
[root@localhost ~]# vim /etc/ssh/sshd_config
······
#PubkeyAuthentication yes '密鑰對驗(yàn)證開啟 是'
#PasswordAuthentication yes '身份密碼驗(yàn)證 是'
AuthorizedKeysFile .ssh/authorized_keys '密鑰對公鑰庫文件路徑'
啟用密碼密碼驗(yàn)證、密鑰對驗(yàn)證、指定公鑰庫位置
ssh user@host
ssh 被連接的主機(jī)的本地用戶名@主機(jī)名
選項(xiàng) -p 即 指定端口號(hào)
scp user@host:file 1 file2
復(fù)制目標(biāo)主機(jī)下面的file文件到自己的file2下
scp file1 user@host:file2
復(fù)制自己的file1下的文件到目標(biāo)主機(jī)的file1下
sftp user@host
進(jìn)入到目標(biāo)主機(jī)的sftp模式
test01 的ip地址為192.168.139.128
test02的ip地址為192.168.139.129
[root@test01 ~]# cd /etc/ssh '切換到/etc/ssh目錄下'
[root@test01 ssh]# ls
moduli ssh_host_ecdsa_key ssh_host_ed25519_key.pub
ssh_config ssh_host_ecdsa_key.pub ssh_host_rsa_key
sshd_config ssh_host_ed25519_key ssh_host_rsa_key.pub
[root@test01 ssh]# vim sshd_config '編輯服務(wù)端配置文件'
# semanage port -a -t ssh_port_t -p tcp #PORTNUMBER
16 #
17 Port 22 '端口號(hào)22,去掉#啟用'
18 #AddressFamily any
19 #ListenAddress 0.0.0.0
20 #ListenAddress ::
21
22 HostKey /etc/ssh/ssh_host_rsa_key
23 #HostKey /etc/ssh/ssh_host_dsa_key
24 HostKey /etc/ssh/ssh_host_ecdsa_key
25 HostKey /etc/ssh/ssh_host_ed25519_key
26
[root@test01 ssh]# systemctl restart sshd '重啟sshd服務(wù)'
[root@test02 ~]# ssh root@192.168.139.128 '連接開啟遠(yuǎn)程服務(wù)的主機(jī),以root身份登陸'
The authenticity of host '192.168.139.128 (192.168.139.128)' can't be established.
ECDSA'指密鑰對' key fingerprint is SHA256:dXWxtS2ShXQgfb7R672V7+l3i7rGqHBbIB5MTcFnAws.
ECDSA'指密鑰對' key fingerprint is MD5:59:fb:20:f0:28:96:5e:14:90:82:63:c9:ae:67:d6:e9.
Are you sure you want to continue connecting (yes/no)? yes
Warning: Permanently added '192.168.139.128' (ECDSA) to the list of known hosts.
root@192.168.139.128's password:
Last login: Wed Nov 20 17:13:57 2019
[root@test01 ~]# '注意主機(jī)名,此時(shí)已經(jīng)遠(yuǎn)程登陸成功'
[root@test01 ~]# ifconfig '查看自身的i網(wǎng)卡(此時(shí)已經(jīng)遠(yuǎn)程到test01上)'
ens33: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500
inet 192.168.139.128 netmask 255.255.255.0 broadcast 192.168.139.255
[root@test01 ~]# exit '退出'
logout
Connection to 192.168.139.128 closed.
[root@test02 ~]# ifconfig '查看自身的主機(jī)名,test02的主機(jī)名'
ens33: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500
inet 192.168.139.129 netmask 255.255.255.0 broadcast 192.168.139.255
[root@test02 ~]# ssh gsy@192.168.139.128 ''用gsy的身份去登陸,也可以
gsy@192.168.139.128's password:
Last login: Wed Nov 20 18:07:37 2019
[gsy@test01 ~]$ exit '退出'
logout
Connection to 192.168.139.128 closed.
遠(yuǎn)程連接目標(biāo)主機(jī)時(shí),使用root或普通用戶都可以
[root@test01 ssh]# vim /etc/ssh/sshd_config '配置28的sshd的服務(wù)端配置文件'
38 PermitRootLogin no '第38行取消注釋符,root登陸否'
[root@test01 ssh]# systemctl restart sshd '重啟ssh服務(wù)以生效配置'
[root@test02 ~]# ssh root@192.168.139.128 '去連28,使用root身份,'
The authenticity of host '192.168.139.128 (192.168.139.128)' can't be established.
ECDSA key fingerprint is SHA256:dXWxtS2ShXQgfb7R672V7+l3i7rGqHBbIB5MTcFnAws.
ECDSA key fingerprint is MD5:59:fb:20:f0:28:96:5e:14:90:82:63:c9:ae:67:d6:e9.
Are you sure you want to continue connecting (yes/no)? yes
Warning: Permanently added '192.168.139.128' (ECDSA) to the list of known hosts.
root@192.168.139.128's password:
Permission denied, please try again. '拒絕權(quán)限,請重試'
root@192.168.139.128's password:
[root@test02 ~]#
[root@test02 ~]# ssh gsy@192.168.139.128 '使用gsy身份去連接,沒問題'
gsy@192.168.139.128's password:
Last login: Wed Nov 20 18:08:14 2019 from 192.168.139.129
[gsy@test01 ~]$
[gsy@test01 ~]$ su - root '然后su切換到root'
Password:
Last login: Wed Nov 20 18:30:29 CST 2019 on pts/5
Last failed login: Wed Nov 20 18:32:37 CST 2019 on pts/5
There was 1 failed login attempt since the last successful login.
[root@test01 ~]# '成功'
permission denied 權(quán)限拒絕
為了不讓普通用戶與root之間隨意切換,可以在服務(wù)端28 配置pam.d/su,啟用pam.d/su后,不在wheel組內(nèi)的用戶無法
[root@test01 ssh]# vim /etc/pam.d/su '編輯對應(yīng)的配置文件'
6 auth required pam_wheel.so use_uid '取消注釋,啟用pam.d的su功能'
[root@test01 ssh]# useradd lisi '新創(chuàng)建用戶lisi,該用戶不在wheel組內(nèi)'
[root@test01 ssh]# passwd lisi
Changing password for user lisi.
New password:
BAD PASSWORD: The password is shorter than 8 characters
Retype new password:
passwd: all authentication tokens updated successfully.
[root@test02 ~]# ssh lisi@192.168.139.128 '用29去鏈接28'
lisi@192.168.139.128's password:
[lisi@test02 ~]$ 'lisi登陸成功'
[lisi@test02 ~]$ su - root 'su 切換root'
密碼:
su: 拒絕權(quán)限 '失敗'
[root@test01 ssh]# vim /etc/ssh/sshd_config '給28配置sshd_config'
21 AllowUsers gsy '手動(dòng)添加白名單,即只允許gsy登陸'
[root@test01 ssh]# systemctl restart sshd '重啟sshd服務(wù)'
[root@test02 ~]# ssh gsy@192.168.139.128 '以gsy身份,29遠(yuǎn)程28'
gsy@192.168.139.128's password:
Last failed login: Wed Nov 20 18:51:43 CST 2019 from 192.168.139.129 on ssh:notty
There was 1 failed login attempt since the last successful login.
Last login: Wed Nov 20 18:48:54 2019 from 192.168.139.128
[gsy@test01 ~]$ logout '登陸成功,然后退出'
Connection to 192.168.139.128 closed.
[root@test02 ~]# ssh root@192.168.139.128 '以root身份29去遠(yuǎn)程28'
root@192.168.139.128's password: '輸入密碼'
Permission denied, please try again. '權(quán)限拒絕,請重試'
root@192.168.139.128's password:
Permission denied, please try again.
[root@test01 ssh]# vim /etc/hosts '此時(shí)在28,以hosts文件為實(shí)驗(yàn)'
test01 192.168.139.128 '增加內(nèi)容'
test02 192.168.139.129 '增加內(nèi)容'
[root@test01 ssh]# vim /etc/ssh/sshd_config '去配置sshd'
#AllowUsers gsy '取消白名單,即所有人都可登錄'
PermitRootLogin no '注釋掉遠(yuǎn)程root登陸 否'
[root@test01 ssh]# systemctl restart sshd '重啟sshd服務(wù)'
[root@test02 ~]# ssh root@192.168.139.128 '以root身份29去遠(yuǎn)程28'
root@192.168.139.128's password:
Last failed login: Wed Nov 20 19:05:55 CST 2019 from 192.168.139.129 on ssh:notty
There were 8 failed login attempts since the last successful login.
Last login: Wed Nov 20 18:41:42 2019 '登陸成功'
[root@test01 ssh]# scp /etc/hosts root@192.168.139.129:etc/hosts
'此時(shí)在28上,scp復(fù)制 本地 /etc/hosts文件 到29:/etc/hosts'
The authenticity of host '192.168.139.129 (192.168.139.129)' can't be established.
ECDSA key fingerprint is SHA256:+uy+1TNy69jB97B7+AoYqhNEaBi42DuOYb0oE4pJ8s0.
ECDSA key fingerprint is MD5:00:78:0c:c1:c2:7b:01:45:7c:31:c2:3b:53:4d:5c:10.
Are you sure you want to continue connecting (yes/no)? yes '詢問是否連接,選擇是'
Warning: Permanently added '192.168.139.129' (ECDSA) to the list of known hosts.
root@192.168.139.129's password:
hosts 100% 204 87.9KB/s 00:00 '顯示進(jìn)度'
[root@test01 ssh]#
[root@test01 ssh]# ssh root@192.168.139.129 '以root身份28遠(yuǎn)程29'
root@192.168.139.129's password:
Last login: Wed Nov 20 19:18:41 2019 from 192.168.139.129
[root@test02 ~]# cat /etc/hosts '查看29下的/etc/hosts文件'
127.0.0.1 localhost localhost.localdomain localhost4 localhost4.localdomain4
::1 localhost localhost.localdomain localhost6 localhost6.localdomain6
test01 192.168.139.128
test02 192.168.139.129
[root@test02 ~]# logout '注銷登陸'
Connection to 192.168.139.129 closed.
[root@test01 ssh]# cd /opt/
[root@test01 opt]# ls
rh
[root@test01 opt]# touch abc.txt '在本地創(chuàng)建空文件'
[root@test01 opt]# scp /opt/abc.txt root@192.168.139.129:/home/
'把本地的/opt/abc.txt文件 以root身份 復(fù)制到192.168.139.129主機(jī)的/home/目錄下'
root@192.168.139.129's password: '密碼確認(rèn)'
abc.txt 100% 0 0.0KB/s 00:00
[root@test01 opt]#
[root@test02 ~]# cd /home
[root@test02 home]# ls
abc.txt gsy
[root@test02 home]# vim /etc/ssh/sshd_config '修改sshd_config服務(wù)端配置'
Port 22 '開啟接口'
[root@test02 home]# systemctl restart sshd '重啟'
[root@test02 home]# mkdir abc
[root@test01 opt]# scp /opt/abc.txt gsy@192.168.139.129:/home/abc/
gsy@192.168.139.129's password:
scp: /home/abc//abc.txt: Permission denied '復(fù)制失敗'
[root@test02 home]# ls -al
total 0
drwxr-xr-x. 4 root root 43 Nov 20 19:32 .
dr-xr-xr-x. 17 root root 224 Oct 24 15:42 ..
'drwxr-xr-x. 2 root root 6 Nov 20 19:32 abc '權(quán)限不夠'
-rw-r--r--. 1 root root 0 Nov 20 19:22 abc.txt
drwx------. 3 gsy gsy 78 Oct 24 15:36 gsy
[root@test02 home]# chmod 777 abc
[root@test02 home]# ls -al
total 0
drwxr-xr-x. 4 root root 43 Nov 20 19:32 .
dr-xr-xr-x. 17 root root 224 Oct 24 15:42 ..
'drwxrwxrwx. 2 root root 6 Nov 20 19:32 abc
-rw-r--r--. 1 root root 0 Nov 20 19:22 abc.txt
drwx------. 3 gsy gsy 78 Oct 24 15:36 gsy
[root@test02 home]#
[root@test01 opt]# scp /opt/abc.txt gsy@192.168.139.129:/home/abc/
'重試'
gsy@192.168.139.129's password: '可以了'
abc.txt 100% 0 0.0KB/s 00:00
然后到29主機(jī)上查看驗(yàn)證
[root@test02 home]# ls -al abc
total 0
drwxrwxrwx. 2 root root 21 Nov 20 19:38 .
drwxr-xr-x. 4 root root 43 Nov 20 19:32 ..
'-rw-r--r--. 1 gsy gsy 0 Nov 20 19:38 abc.txt
以什么用戶傳過去的,就會(huì)以該用戶的屬主寫入
[root@test01 opt]# scp root@192.168.139.129:/home/gsy.txt /opt
'在28上,從29主機(jī)上以root身份去復(fù)制/home/gsy.txt文件 到/opt下'
root@192.168.139.129's password:
gsy.txt '成功' 100% 4 1.4KB/s 00:00
[root@test01 opt]# ls -l
total 4
-rw-r--r--. 1 root root 0 Nov 20 19:21 abc.txt
'-rw-r--r--. 1 root root 4 Nov 20 19:46 gsy.txt'
drwxr-xr-x. 2 root root 6 Mar 26 2015 rh
[root@test01 opt]# cat gsy.txt
gsy
[root@test01 opt]#
想要ssh遠(yuǎn)程其他,就需要吧其他的的權(quán)限放開
[root@test01 ~]# sftp root@192.168.139.129 'ftp上下載方式連接29'
root@192.168.139.129's password:
Connected to 192.168.139.129.
sftp>
sftp> ls -a
. .. .ICEauthority
.Xauthority .bash_history .bash_logout
.bash_profile .bashrc .cache
.config .cshrc .dbus
.esd_auth .local .mozilla
.ssh .tcshrc .viminfo
anaconda-ks.cfg initial-setup-ks.cfg 下載
公共 圖片 文檔
桌面 模板 視頻
音樂
sftp> cd /opt
sftp> ls
rh
sftp> mkdir aaa
sftp> ls
aaa rh
sftp> rm -rf aaa
rm: Invalid flag -r
sftp>
ls
aaa rh
sftp>
sftp> help
Available commands:
bye Quit sftp
cd path Change remote directory to 'path'
chgrp grp path Change group of file 'path' to 'grp'
chmod mode path Change permissions of file 'path' to 'mode'
chown own path Change owner of file 'path' to 'own'
df [-hi] [path] Display statistics for current directory or
filesystem containing 'path'
exit Quit sftp
get [-afPpRr] remote [local] Download file
reget [-fPpRr] remote [local] Resume download file
reput [-fPpRr] [local] remote Resume upload file
help Display this help text
lcd path Change local directory to 'path'
lls [ls-options [path]] Display local directory listing
lmkdir path Create local directory
ln [-s] oldpath newpath Link remote file (-s for symlink)
lpwd Print local working directory
ls [-1afhlnrSt] [path] Display remote directory listing
lumask umask Set local umask to 'umask'
mkdir path Create remote directory
progress Toggle display of progress meter
put [-afPpRr] local [remote] Upload file
pwd Display remote working directory
quit Quit sftp
rename oldpath newpath Rename remote file
rm path Delete remote file
rmdir path Remove remote directory
symlink oldpath newpath Symlink remote file
version Show SFTP version
!command Execute 'command' in local shell
! Escape to local shell
? Synonym for help
sftp> rmdir aaa
sftp> ls
rh
sftp>
在sftp模式下,命令跟linux的命令有些不一樣
[root@test02 ~]# ssh-keygen rsa ‘創(chuàng)建密鑰對的選項(xiàng)’
Too many arguments.
usage: ssh-keygen [-q] [-b bits] [-t dsa | ecdsa | ed25519 | rsa | rsa1]
[-N new_passphrase] [-C comment] [-f output_keyfile]
ssh-keygen -p [-P old_passphrase] [-N new_passphrase] [-f keyfile]
ssh-keygen -i [-m key_format] [-f input_keyfile]
ssh-keygen -e [-m key_format] [-f input_keyfile]
ssh-keygen -y [-f input_keyfile]
ssh-keygen -c [-P passphrase] [-C comment] [-f keyfile]
ssh-keygen -l [-v] [-E fingerprint_hash] [-f input_keyfile]
ssh-keygen -B [-f input_keyfile]
ssh-keygen -D pkcs11
ssh-keygen -F hostname [-f known_hosts_file] [-l]
ssh-keygen -H [-f known_hosts_file]
ssh-keygen -R hostname [-f known_hosts_file]
ssh-keygen -r hostname [-f input_keyfile] [-g]
ssh-keygen -G output_file [-v] [-b bits] [-M memory] [-S start_point]
ssh-keygen -T output_file -f input_file [-v] [-a rounds] [-J num_lines]
[-j start_line] [-K checkpt] [-W generator]
ssh-keygen -s ca_key -I certificate_identity [-h] [-n principals]
[-O option] [-V validity_interval] [-z serial_number] file ...
ssh-keygen -L [-f input_keyfile]
ssh-keygen -A
ssh-keygen -k -f krl_file [-u] [-s ca_public] [-z version_number]
file ...
ssh-keygen -Q -f krl_file file ...
[root@test02 ~]# ssh-keygen -t rsa '創(chuàng)建密鑰對 -t '
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:ZL4EmtVT8fXoCPScBgL7bldPv380zK93PQnA9kmORF8 root@test02
The key's randomart image is:
+---[RSA 2048]----+
| ... =. . |
| o + * o E |
| + = + B o .|
| + * . B = |
| o S o O * |
| o . o B =.|
| + . o.*|
| . . oB|
| .+*|
+----[SHA256]-----+
[root@test02 ~]# ls -a
. .bash_logout .dbus .ssh 圖片
.. .bash_profile .esd_auth .tcshrc 文檔
123123 .bashrc .ICEauthority .viminfo 桌面
123123.pub .cache initial-setup-ks.cfg .Xauthority 模板
anaconda-ks.cfg .config .local 下載 視頻
.bash_history .cshrc .mozilla 公共 音樂
[root@test02 ~]# cd .ssh
[root@test02 .ssh]# ls
id_rsa id_rsa.pub known_hosts
[root@test02 .ssh]# ssh-copy-id -i id_rsa.pub gsy@192.168.139.128
'復(fù)制密鑰對的公鑰復(fù)制到28服務(wù)端,以gsy身份'
/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
gsy@192.168.139.128's password: '輸入密碼'
Number of key(s) added: 1
Now try logging into the machine, with: "ssh 'gsy@192.168.139.128'"
and check to make sure that only the key(s) you wanted were added.
[root@test01 ~]# cd /home/gsy
[root@test01 gsy]# ls
下載 公共 圖片 文檔 桌面 模板 視頻 音樂
[root@test01 gsy]# ls -a
. .bash_logout .cache .ICEauthority .ssh 圖片 模板
.. .bash_profile .config .local 下載 文檔 視頻
.bash_history .bashrc .esd_auth .mozilla 公共 桌面 音樂
[root@test01 gsy]# cd .ssh
[root@test01 .ssh]# ls '驗(yàn)證是否成功復(fù)制到28服務(wù)端'
authorized_keys
[root@test02 ~]# ssh gsy@192.168.139.128 '再次遠(yuǎn)程登陸服務(wù)端28'
Enter passphrase for key '/root/.ssh/id_rsa': '輸入之前輸入的密碼'
Last failed login: Wed Nov 20 20:17:55 CST 2019 from 192.168.139.129 on ssh:notty
There was 1 failed login attempt since the last successful login.
Last login: Wed Nov 20 18:51:51 2019 from 192.168.139.129
[gsy@test01 ~]$ '登陸成功'
[gsy@test01 ~]$ exit
logout
Connection to 192.168.139.128 closed.
[root@test02 ~]# ls -a
. .bash_logout .dbus .ssh 圖片
.. .bash_profile .esd_auth .tcshrc 文檔
123123 .bashrc .ICEauthority .viminfo 桌面
123123.pub .cache initial-setup-ks.cfg .Xauthority 模板
anaconda-ks.cfg .config .local 下載 視頻
.bash_history .cshrc .mozilla 公共 音樂
[root@test02 ~]# ls -a .ssh
. .. id_rsa id_rsa.pub known_hosts
[root@test02 ~]# ssh-agent bash '創(chuàng)建自動(dòng)代理功能'
[root@test02 ~]# ssh-add '免交互'
Enter passphrase for /root/.ssh/id_rsa: '輸入密碼確認(rèn)'
Identity added: /root/.ssh/id_rsa (/root/.ssh/id_rsa)
[root@test02 ~]#
[root@test02 ~]# ssh gsy@192.168.139.128 '再次以gsy身份去登陸28服務(wù)端'
Last login: Wed Nov 20 21:33:22 2019 from 192.168.139.130 '網(wǎng)絡(luò)被切換,客戶機(jī)IP地址改變'
ssh-agent bash 創(chuàng)建自動(dòng)代理功能
ssh-add 免交互
可以用于在shelle腳本遠(yuǎn)程
其中,ssh就是能夠被它管控的服務(wù)
[root@test01 .ssh]# ldd `which sshd`
linux-vdso.so.1 => (0x00007ffd5eb16000)
libfipscheck.so.1 => /lib64/libfipscheck.so.1 (0x00007f4e20f2b000)
libwrap.so.0 => /lib64/libwrap.so.0 (0x00007f4e20d20000)
libaudit.so.1 => /lib64/libaudit.so.1 (0x00007f4e20af7000)
libpam.so.0 => /lib64/libpam.so.0 (0x00007f4e208e8000)
libselinux.so.1 => /lib64/libselinux.so.1 (0x00007f4e206c1000)
libsystemd.so.0 => /lib64/libsystemd.so.0 (0x00007f4e20698000)
libcrypto.so.10 => /lib64/libcrypto.so.10 (0x00007f4e20237000)
libdl.so.2 => /lib64/libdl.so.2 (0x00007f4e20033000)
libldap-2.4.so.2 => /lib64/libldap-2.4.so.2 (0x00007f4e1fdde000)
liblber-2.4.so.2 => /lib64/liblber-2.4.so.2 (0x00007f4e1fbcf000)
libutil.so.1 => /lib64/libutil.so.1 (0x00007f4e1f9cc000)
libz.so.1 => /lib64/libz.so.1 (0x00007f4e1f75000)
libcrypt.so.1 => /lib64/libcrypt.so.1 (0x00007f4e1f57e000)
libresolv.so.2 => /lib64/libresolv.so.2 (0x00007f4e1f364000)
libgssapi_krb5.so.2 => /lib64/libgssapi_krb5.so.2 (0x00007f4e1f116000)
libkrb5.so.3 => /lib64/libkrb5.so.3 (0x00007f4e1ee2e000)
libk5crypto.so.3 => /lib64/libk5crypto.so.3 (0x00007f4e1ebfb000)
libcom_err.so.2 => /lib64/libcom_err.so.2 (0x00007f4e1e9f6000)
libc.so.6 => /lib64/libc.so.6 (0x00007f4e1e633000)
libnsl.so.1 => /lib64/libnsl.so.1 (0x00007f4e1e41a000)
libcap-ng.so.0 => /lib64/libcap-ng.so.0 (0x00007f4e1e213000)
libpcre.so.1 => /lib64/libpcre.so.1 (0x00007f4e1dfb1000)
/lib64/ld-linux-x86-64.so.2 (0x0000562f68c55000)
libcap.so.2 => /lib64/libcap.so.2 (0x00007f4e1ddac000)
libm.so.6 => /lib64/libm.so.6 (0x00007f4e1daa9000)
librt.so.1 => /lib64/librt.so.1 (0x00007f4e1d8a1000)
liblzma.so.5 => /lib64/liblzma.so.5 (0x00007f4e1d67b000)
libgcrypt.so.11 => /lib64/libgcrypt.so.11 (0x00007f4e1d3f9000)
libgpg-error.so.0 => /lib64/libgpg-error.so.0 (0x00007f4e1d1f4000)
libdw.so.1 => /lib64/libdw.so.1 (0x00007f4e1cfad000)
libgcc_s.so.1 => /lib64/libgcc_s.so.1 (0x00007f4e1cd96000)
libpthread.so.0 => /lib64/libpthread.so.0 (0x00007f4e1cb7a000)
libsasl2.so.3 => /lib64/libsasl2.so.3 (0x00007f4e1c95d000)
libssl3.so => /lib64/libssl3.so (0x00007f4e1c710000)
libsmime3.so => /lib64/libsmime3.so (0x00007f4e1c4e9000)
libnss3.so => /lib64/libnss3.so (0x00007f4e1c1bf000)
libnssutil3.so => /lib64/libnssutil3.so (0x00007f4e1bf91000)
libplds4.so => /lib64/libplds4.so (0x00007f4e1bd8d000)
libplc4.so => /lib64/libplc4.so (0x00007f4e1bb88000)
libnspr4.so => /lib64/libnspr4.so (0x00007f4e1b949000)
libfreebl3.so => /lib64/libfreebl3.so (0x00007f4e1b746000)
libkrb5support.so.0 => /lib64/libkrb5support.so.0 (0x00007f4e1b537000)
libkeyutils.so.1 => /lib64/libkeyutils.so.1 (0x00007f4e1b333000)
libattr.so.1 => /lib64/libattr.so.1 (0x00007f4e1b12d000)
libelf.so.1 => /lib64/libelf.so.1 (0x00007f4e1af15000)
libbz2.so.1 => /lib64/libbz2.so.1 (0x00007f4e1ad04000)
查詢功能模塊 `后面接命令
[root@localhost ~]# echo "sshd:61.63.65.67,192.168.2.*" > /etc/hosts.allow
[root@localhost ~]# vi /etc/hosts.allow
sshd:61.63.65.67,192.168.2.*
[root@localhost ~]# echo "sshd:ALL" > /etc/hosts.deny
[root@localhost ~]# vi /etc/hosts.deny
sshd:ALL
[root@localhost ~]#
優(yōu)先讀取allow,然后再度deny
如果只想禁止某些主機(jī)登陸,則只做黑名單,白名單不寫
ssh 22端口
服務(wù)端配置文件 /etc/ssh/sshd_config
Port 22 '端口號(hào)'
ListenAddress 192.168.155.155 '監(jiān)聽地址'
Protocol 2 '版本號(hào)'
UserDNS no 'DNS反向解析,否'
LoginGraceTime 2m '登陸時(shí)間 2m'
PermitRootLogin no '允許root登陸 否'
MaxAuthTries 6 '最大嘗試登陸次數(shù) 6 次'
PermitEmptyPasswords no '禁止空密碼'
AllowUsers gsy lisi@192.168.88.88
'只允許gsy登陸,lisi從192.168.88.88登陸,別人都不行'
PasswordAuthentication yes '需要密碼驗(yàn)證 是'
PubkeyAuthentication yes '開啟密鑰對驗(yàn)證 是'
AuthorizedKeyFile .ssh/authorized_keys '密鑰對文件位置'
ssh 用戶名@ip地址 -p 指定端口號(hào)
scp 要復(fù)制的文件 復(fù)制到的目標(biāo)位置
scp 用戶名@ipdizhi:源文件路徑 目標(biāo)路徑
sftp 用戶名@ip地址
ssh-keygen -t rsa(或dsa算法) 創(chuàng)建密鑰對
ssh-copy -i 公鑰文件路徑 用戶名@目標(biāo)ip地址
ssh-copy -i ~/.ssh/id_rsa.pub gsy@192.168.88.88
ssh-agent bash 創(chuàng)建自動(dòng)代理功能
ssh-add 免交互
ldd ·which sshd·
訪問控制策略的配置文件
/etc/hosts.allow
/etc/hosts.deny
如果做黑名單,白名單可以不寫
網(wǎng)站題目:理論:linux遠(yuǎn)程控制openssh詳細(xì)講解
文章來源:http://jinyejixie.com/article44/pdcghe.html
成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供網(wǎng)站導(dǎo)航、營銷型網(wǎng)站建設(shè)、域名注冊、App設(shè)計(jì)、ChatGPT、企業(yè)網(wǎng)站制作
聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請盡快告知,我們將會(huì)在第一時(shí)間刪除。文章觀點(diǎn)不代表本網(wǎng)站立場,如需處理請聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時(shí)需注明來源: 創(chuàng)新互聯(lián)