嵌入式Linux入门3:Linux服务器搭建 | 迟思堂工作室
A-A+

嵌入式Linux入门3:Linux服务器搭建

2017-07-08 16:22 嵌入式Linux 暂无评论 阅读 1,747 次

本文介绍在Linux系统(ubuntu 16.04)中搭建各种服务器的方法,包括NFS、samba、ssh、telnet。

一、ssh服务器

Linux(包括服务器、设备端)开启SSH,使用如ssh secure shell client等客户端工具连接、登陆,找到对应目录,可实现相互拷贝。

1、安装:
sudo apt-get install openssh-server

2、重启:
sudo/etc/init.d/ssh restart

3、修改端口
SSH默认服务端口为22,可修改为其它端口,如220,修改配置文件/etc/ssh/sshd_config

Port 22
改为
Port 220
即可

 

附:SSH Secure Shell Client无法连接ubuntu解决方法

1、编辑/etc/ssh/sshd_config配置文件。

1.1、

PermitRootLogin prohibit-password
改为
PermitRootLogin yes

1.2、最后添加:
Ciphers aes128-cbc,aes192-cbc,aes256-cbc,aes128-ctr,aes192-ctr,aes256-ctr,3des-cbc,arcfour128,arcfour256,arcfour,blowfish-cbc,cast128-cbc
MACs hmac-md5,hmac-sha1,umac-64@openssh.com,hmac-ripemd160,hmac-sha1-96,hmac-md5-96
KexAlgorithms diffie-hellman-group1-sha1,diffie-hellman-group14-sha1,diffie-hellman-group-exchange-sha1,diffie-hellman-group-exchange-sha256,ecdh-sha2-nistp256,ecdh-sha2-nistp384,ecdh-sha2-nistp521,diffie-hellman-group1-sha1,curve25519-sha256@libssh.org

2、重启ssh服务
sudo service ssh restart

再次使用SSH Secure Shell Client即可连接。

二、samba服务器

Linux主机搭建samba服务器后,可以使用windows连接Linux,并建立硬盘映射,这样,就可以将主机当成Windows一个硬盘使用。

1、samba的安装:
sudo apt-get install samba
sudo apt-get install smbclient (客户端,可选)
注:如果安装有错误,则要更新源:
sudo apt-get update

2、创建共享目录(可选):
mkdir /home/latelee/share
sodu chmod 777 /home/latelee/share

3、创建Samba配置文件:
1. 保存现有的配置文件(可选)
sudo cp /etc/samba/smb.conf /etc/samba/smb.conf.bak
2. 修改现配置文件
sudo vim /etc/samba/smb.conf
在smb.conf最后添加
[home] # 用于显示在windows的名称
comment = samba home # 注释,不要也可以
path = /home/latelee # 共享目录路径
writable = yes # 可写
browseable = yes # 可看
guest ok = no # 不允许guest
注:格式如上,路径根据实际情况改

4、创建samba帐户
sudo touch /etc/samba/smbpasswd (此步不要也行)
sudo smbpasswd -a latelee(用户名)

New SMB password:(此处密码,建议与登陆密码相同)
Retype new SMB password:(此处密码,建议与登陆密码相同)

注:如果没有第四步,登录时会提示 session setup failed: NT_STATUS_LOGON_FAILURE

5、重启samba服务器
fc10:
/etc/init.d/smb  restart

ubuntu:
sudo /etc/init.d/samba restart
sudo /etc/init.d/smbd restart (此步可不要)
注:不同版本路径、名称可能不同,根据实际情况尝试

6、测试 (不要也行)
smbclient -L //localhost/共享目录

7、使用windows连接

三、telnet服务器

1、安装:
# 默认源没有此包,要update源
sudo apt-get update
sudo apt-get install xinetd telnetd

2、配置

修改文件 /etc/xinetd.conf
(xinetd默认为此文件)
# new add by Late Lee
service telnet
{
disable = no
flags = REUSE
socket_type = stream
wait = no
user = root (存疑:root表示执行程序的权限还是登陆用户?从测试中看,是root权限,换其它用户名,会提示telnetd /usr/lib/telnet login permission denied)
server = /usr/sbin/in.telnetd
log_on_failure += USERID
}

 

3、修改端口
修改/etc/services
将telnet的23改为其它的不冲突的端口号,如250。

4、重启
/etc/init.d/xinetd restart

5、登陆

命令:telnet ip 端口号

6、允许root登陆
ubuntu不允许root用户用telnet来登陆,但可以使用非root用户,与ssh类似。

如果一定要用root登陆,方法有2种:
1、将/etc/securetty文件改名
2、在/etc/securetty文件最后添加
# add pst by Late Lee
pts/0
pts/1
pts/2
pts/3
pts/4
pts/5
pts/6
pts/7
pts/8
pts/9

说明:
securetty文件规定了root可以从哪些终端登陆,像ssh、telnet等是用伪终端pts,另外该文件还有如标准终端的tty*(按Ctrl+Alt+数字登陆)、串口ttyS*、ttyUSB*、ttyO*(OMAP系的串口),等等

四、NFS服务器

使用nfs挂载之后,可以将远程主机目录作为本地目录那样使用。十分方便。

1、安装
sudo apt-get install nfs-kernel-server
注:如果失败,可以再尝试一次,或者用命令:sudo apt-get update

2、配置
编辑文件/etc/exports
加入下列语句:
[共享目录绝对路径] *(rw,no_root_squash,no_all_squash,sync)

例如:
/opt *(rw,no_root_squash,no_all_squash,sync)

注:可添加多个共享目录

3、启动NFS服务
sudo /etc/init.d/nfs-kernel-server restart

4、ARM-Linux挂载测试
命令示例:
mount -t nfs -o nolock 172.18.18.18:/opt /mnt/nfs

 

李迟 2017.7.8 周六 傍晚

 



如果本文对阁下有帮助,不妨赞助笔者以输出更多好文章,谢谢!
donate



标签:

给我留言