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位系统)
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章