ssh遠程登錄(telnet)
安裝包:openssh-5.3p1-84.1.el6.x86_64.rpm
配置文件:/etc/ssh/sshd_config
端口:22
日志:/var/log/secure
啟動服務:service sshd restart
登錄
[root@robin ~]# ssh root@192.168.10.120
[root@robin ~]# ssh zhb@192.168.10.120
遠程拷貝
[root@test tmp]# scp /tmp/aa.txt 172.16.110.1:/tmp/
[root@robin ~]# scp /root/install.log 172.16.110.30:/tmp/
[root@robin ~]# scp 172.16.110.30:/tmp/aa.txt 172.16.110.40:/tmp/
遠程執行命令
[root@robin ~]# ssh 172.16.110.30 ls /root/
[root@robin ~]# ssh 172.16.110.30 useradd robin
查看登錄信息
[root@robin ~]# w
[root@robin ~]# wall 可以一次輸入多行,多字符串,按ctrl+d時需要新起一行
shutdown now !!! save your file !!!!
ctrl+d
[root@robin ~]# wall stop 直接向對方顯示,單只能顯示一次,并且直傳一個字符穿,只能發送一次
[root@robin ~]# write root /dev/pts/12 直接對另一端/pts/12登錄的用戶root對話,enter發送,多次發送。
stop now!!!!
ctrl+d
[root@robin ~]# netstat -anplt -a all -n 取消解析 -p pid -l 詳細信息 -t tcp
[root@robin ~]# netstat -anplt| grep 172.16.110.37
登錄的歷史信息
[root@robin ~]# last
[root@robin ~]# lastlog 系統用戶登錄情況
[root@robin ~]# whoami 當前用戶身份
root
[root@robin ~]# who i am 原始登錄用戶身份
root pts/0 2015-12-02 14:56 (:0.0)
密鑰登錄
[root@robin ~]# ssh-keygen 產生密鑰
[root@robin ~]# ls /root/.ssh/
id_rsa id_rsa.pub known_hosts
私鑰 公鑰 記錄主機信息
[root@robin ~]# ssh-copy-id -i 172.16.110.20 或者
[root@robin ~]# scp /root/.ssh/id_rsa.pub 172.16.110.20:/root/.ssh/authorized_keys
禁止密碼登錄
[root@robin ~]# vim /etc/ssh/sshd_config
PasswordAuthentication no
修改端口
[root@robin ~]# vim /etc/ssh/sshd_config
Port 2222
登錄
[root@localhost ~]# ssh 172.16.110.1 -p 22222
[root@robin ~]# scp -P 22222 172.16.110.1:/root/install.log /tmp/
限制root登錄
PermitRootLogin no|yes
限制用戶登錄
DenyUsers 用戶名
ssh日志的管理
[root@robin ~]# vim /etc/ssh/sshd_config
SyslogFacility AUTHPRIV
[root@robin ~]# vim /etc/rsyslog.conf
authpriv.* /var/log/secure
使用自定義日志接口
SyslogFacility local2
local2.* /var/log/ssh.log
用戶使用自定義日志接口
[root@robin ~]# logger -p local2.debug -f /var/log/ssh.log hello world!!!!
作業:多主機互相登錄
文件服務器
nfs網絡文件系統
配置文件:/etc/exports
端口:2049
啟動服務:service nfs restart
service rpcbind restart
服務端
[root@robin ~]# vim /etc/exports
/nfs 172.16.110.3(rw,sync) 一臺服務器
/nfs 172.16.110.3(rw,sync) 172.16.110.4/32(ro) 多臺
/nfs 172.16.110.0/24(rw,sync) 網端
[root@robin nfs]# chmod 757 /nfs/
客戶端
[root@data1 ~]# showmount -e 172.16.110.1
/nfs 172.16.110.3
[root@data1 ~]# mount -t nfs 172.16.110.1:/nfs /mnt
不修改權限,客戶端可以寫入
/nfs 172.16.110.3(rw,sync,no_root_squash)
作業:
1.NAS raid+lvm+nfs
2.3自動掛載方式實現nas自動掛載
samba
/etc/samba/ 目錄下的東西不能都刪除
安裝包:samba-3.6.9-151.el6.x86_64.rpm
samba-client-3.6.9-151.el6.x86_64.rpm
配置文件:/etc/samba/smb.conf
啟動服務:service smb restart
匿名配置:
vim /etc/samba/smb.conf
security = share
[test]
comment = test
path = /tmp/test 給777 權限
writable = yes
public = yes
browseable = yes | no 隱藏共享
[root@robin 桌面]# service smb restart
客戶端:
windows
地址欄 \172.16.110.1
linux
[root@robin ~]# smbclient -L //172.16.110.1 查詢
[root@robin ~]# smbclient //172.16.110.1/test
掛載使用
[root@data1 ~]# mount -t cifs //172.16.110.1/test /mnt/
用戶驗證方式
vim /etc/samba/smb.conf
security = user
[kkk]
comment = king dir
path = /tmp/kkk 給文件夾 777的權限
writable = yes
valid users = king @uplooking 允許訪問該共享的用戶
invalid users = harry 禁止訪問的用戶
[root@robin tmp]# useradd king
[root@robin tmp]# smbpasswd -a king
[root@robin tmp]# useradd -G uplooking jerry
[root@robin tmp]# useradd -G uplooking tom
[root@robin tmp]# smbpasswd -a tom
[root@robin tmp]# smbpasswd -a jerry
客戶端:
[root@data1 ~]# smbclient -L //172.16.110.1
[root@data1 ~]# smbclient -U king%123 //172.16.110.1/kkk
[root@data1 ~]# mount -o username=king,password=123 //172.16.110.1/kkk /mnt/
[kkk]
comment = king dir
path = /tmp/kkk
writable = no
valid users = king @uplooking
write list = king
public = yes 公共的
[kkk]
comment = king dir
path = /tmp/kkk
writable = yes
valid users = king @uplooking
read list = king
user模式下實現匿名訪問
security = user
map to guest = bad user
[test]
comment = test
path = /tmp/test
writable = yes
public = yes
guest ok = yes
練習:
1.NAS
2.自動掛載(user)
smb -fstype=cifs,rw,sync,username=king,password=123 ://172.16.110.1/kkk
[boss]
comment = boss
path = /tmp/boss
writable = no
valid user = boss robin zorro king
write list = boss
[cw]
comment = cw
path = /tmp/boss/cw
writable = no
valid user = boss robin tom jerry
write list = robin
[yw]
comment = yw
path = /tmp/boss/yw
writable = no
valid user = boss zorro jack rose
write list = zorro
[kf]
comment = kf
path = /tmp/boss/kf
writable = no
valid user = boss king lili luci
write list = king
[pub]
comment = public
path = /tmp/pub
writable = yes
invalid user = boss
public = yes
查詢所有的smb帳號
[root@robin tmp]# pdbedit -L
刪除
[root@robin tmp]# smbpasswd -x bossl
samba配置中常見錯誤收集
一. Server not using user level security and no password supplied.
tree connect failed: NT_STATUS_BAD_NETWORK_NAME
可能的原因:
1、指定的共享路徑path有誤,path中不能有中文字符,因為有些版本對中文支持不夠好。
2、指定的共享路徑不存在,譬如:smb.conf中這樣配置:
[global]
workgroup = MYGROUP
server string = Linux Samba Server TestServer
security = share
[tangfu]
path = /sysadm
writeable = yes
public = yes
正確的訪問方法應該是:smbclient //samba服務器IP或127.0.0.1/tangfu, 如果這樣訪問:samclient //127.0.0.1/tangfuu
uu 將會出現以上錯誤。
二、Server not using user level security and no password supplied.
Server requested LANMAN password (share-level security) but 'client lanman auth' is disabled
tree connect failed: NT_STATUS_ACCESS_DENIED
可能的原因:
1、在global中配置了security=share,但是在共享片段中沒有配置public = yes。例如:
[global]
workgroup = MYGROUP
security = share
[cs2c-tangfu]
path = /home/tangfu
writeable = yes
browseable = yes
此時無論輸入密碼還是不輸入密碼均會出現上面的錯誤。
2、在global中配置了security=share,但是在共享片段中配置了public = yes。例如:
[global]
workgroup = MYGROUP
security = share
[cs2c-tangfu]
path = /home/tangfu
writeable = yes
browseable = yes
public = yes
此時如果不輸入密碼 可以正常訪問,但是如果輸入密碼會出現以上錯誤。
三、session setup failed: NT_STATUS_LOGON_FAILURE
可能的原因:
1、在global中配置了guest ok = yes或者public = yes(guest ok=yes和public = yes代表的意思差不多 ),或者是在共享片段中配置 配置了guest ok = yes或者public = yes 。例如:
[global]
workgroup = MYGROUP
guest ok = yes
[cs2c-tangfu]
path = /home/tangfu
writeable = yes
browseable = yes
此時如果不輸入密碼可以正常訪問,但是如果輸入密碼會出現以上錯誤。
四、tree connect failed:NET_STATUS_BAD_NETWORK_NAME
可能原因:
1、共享的目錄沒有相應的權限
五、NET_STATUS_NETWORK_ACCESS_DENIED
可能原因:
1.共享目錄沒有權限。