Ubuntu 16.04 安裝後網絡、ssh禁止root、上傳設置

VMware Ubuntu 安裝過程記錄

下載地址

wget http://mirrors.aliyun.com/ubuntu-releases/16.04/ubuntu-16.04.5-server-amd64.iso

1. 設置 ip 固定地址

** 虛擬機網卡模式:橋接模式(自動檢測)
打開 Termainal,查看目前的網址
    ip  a
        1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN group default qlen 1000
        link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
        inet 127.0.0.1/8 scope host lo
        valid_lft forever preferred_lft forever
        inet6 ::1/128 scope host
        valid_lft forever preferred_lft forever
        2: ens33: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UNKNOWN group default qlen 1000
        link/ether 00:0c:29:59:2c:b3 brd ff:ff:ff:ff:ff:ff
        inet 192.168.1.177/24 brd 192.168.1.255 scope global ens33
        valid_lft forever preferred_lft forever
        inet6 fe80::20c:29ff:fe59:2cb3/64 scope link
        valid_lft forever preferred_lft forever
*** 注意查看第二項網卡名字,我這裏叫做 ens33

2. 打開網卡設置文件

cd /etc/network
ls
    if-down.d  if-post-down.d  if-pre-up.d  if-up.d  interfaces  interfaces.d
*** 注意其中 interfaces
開始編輯這個文件 sudo  vi interfaces,加入以下內容,保存重啓
auto ens33
iface ens33  inet static
address 192.168.1.177
netmask 255.255.255.0
gateway 192.168.1.1

重啓networking 服務,直接生效
sudo /etc/init.d/networking restart
或者
cd /etc/init.d/
./networking restart

** 20190124 新安裝的版本 ubuntu 16.04.5 ,以上方式不可以了
	sudo vim /etc/network/interfaces
	最後加上 dns-nameservers 2行,如下:
	
		# The primary network interface
		auto enp0s3
		iface enp0s3 inet static
		address 192.168.1.161
		netmask 255.255.255.0
		gateway 192.168.1.1
		# add by wzh 20190124
		dns-nameservers 223.5.5.5
		dns-search pcat

	sudo /etc/init.d/networking restart
	ping mirrors.aliyun.com

3. 開啓 DNS

1. sudo vi /etc/resolv.conf
	加入一行
		nameserver  114.114.114.114
	保存退出即可

	確認一下
    ping www.baiodu.com
	
2. 重啓networking 服務,直接生效
	sudo /etc/init.d/networking restart

3. 查看當前 DNS
	cat /etc/resolv.conf

4. 開啓 ssh

檢查一下是否已經有 ssh 服務
    ps -ef |grep sshd
    如果找到了 sshd ,說明已經有了,否則,安裝!
    sudo apt-get install openssh-server
    完成之後,再次確認 sshd 服務
    ps -ef |grep ssh
    root      2338     1  0 17:01 ?        00:00:00 /usr/sbin/sshd -D
    root      2402  2338  0 17:03 ?        00:00:00 sshd: dhbm [priv]
    dhbm      2451  2402  0 17:03 ?        00:00:00 sshd: dhbm@pts/4
    dhbm      2502  2452  0 17:11 pts/4    00:00:00 grep --color=auto ssh

5. ssh 192.168.1.177

 首次連接,會出現一些提示,輸入 yes 即可
 如果碰巧,ssh 192.168.1.177 以前鏈接過同樣的地址,會出現錯誤提示
 按照提示,去刪除之前保存過的證書,重新 ssh 即可

禁止 root 遠程登錄

 sudo vim /etc/ssh/sshd_config
 找到 PermitRootLogin ,修改爲 no
 ## by wzh 20180914 allow  root no)
	PermitRootLogin no
重啓 ssh 生效
/etc/init.d/ssh restart

6. 接下來就可以自由的遠程安裝和設置了,主要是下載、複製等操作自由了!

比方說:我這個新 ubuntu vim 也沒有,update 也沒有做過!
    sudoer 也許會用得上 (自己用就不必再建立其他用戶並授權了)

7、ftp 測試

本地先建一個測試文件 test.txt(內容隨意)
遠程先 ssh 登陸,建立一個測試目錄,例如:test
設置該目錄可以讀寫 ( *** 切記!)
 chmod -R 777 test

7.1、 準備上傳

** 開 2 個 terminal,
** Termainl 1 : 
	ssh 192.168.1.177, 並 cd 到指定目錄 /home/dhbm/test
** Terminal 2:
	pwd
	/Users/dhbm
	dhbmdeMacBook-Pro:~ dhbm$ ls test*
	test.db		test.html	test.py		test.txt

7.2、上傳一個文件命令 (在 Terminal 2)

	scp test.txt [email protected]:/home/dhbm/test/

7.3、上傳整個 test123 目錄 到服務器的 test 目錄(成爲 test 目錄的子目錄)

	scp -r test123 [email protected]:/home/dhbm/test
** 驗證:在 Termainl 1 sh上
 	pwd
	/home/dhbm/test/test123
	dhbm@dhbm-virtual-machine:~/test/test123$ ls
	test.html  test.py  test.txt
記錄一下可能要用的
	scp -r lxn0808 [email protected]:/home/dhbm/test

7.4、準備下載

同上,開 2 個 Terminal
下載一個文件 (test.txt)
	** 爲了測試,本地先刪除掉 test.txt
	rm test.txt
	ls test.txt
	ls: test.txt: No such file or directory

7.5、下載單個文件命令 (在 Terminal 2 )

scp [email protected]:/home/dhbm/test/test.txt test.txt
驗證:(在 Terminal 2 )
	ls test.txt
	test.txt

7.6、下載整個 test123 目錄命令 (在 Terminal 2 )

scp -r [email protected]:/home/dhbm/test/test123  test123
驗證:(在 Terminal 2 )
	ls test123
test.html	test.py		test.txt	test123

其他

查看 linux 版本
直接進入到proc 目錄,cd /proc ,可以看到各種信息文件

cat version
		Linux version 4.15.0-29-generic (buildd@lgw01-amd64-021) (gcc version 5.4.0 				20160609 (Ubuntu 5.4.0-6ubuntu1~16.04.10)) #31~16.04.1-Ubuntu SMP Wed Jul 18 				10:19:08 			UTC 2018
		
cat cpuinfo
	processor	: 0
	vendor_id	: GenuineIntel
	cpu family	: 6
	model		: 70
	model name	: Intel(R) Core(TM) i7-4770HQ CPU @ 2.20GHz
	...
getconf LONG_BIT
	32
	(32 代表 32 位系統 ,64 代表 64位系統)
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章