如何在Raspberry PI上设置和使用SSH

SSH is a secure method of logging onto a remote computer. If your Pi is networked, then this can be a handy way of operating it from another computer or just copying files to or from it.

SSH是登录到远程计算机的安全方法。 如果您的Pi已联网,则这可能是从另一台计算机上进行操作或将文件复制到其中或从中复制文件的便捷方法。

First, you have to install the SSH service. This is done by this command:

首先,您必须安装SSH服务。 这是通过以下命令完成的:

sudo apt-get install ssh

sudo apt-get install ssh

After a couple of minutes, this will be complete. You can start the daemon (Unix name for a service) with this command from the terminal:

几分钟后,这将完成。 您可以从终端使用以下命令启动守护程序(服务的Unix名称):

sudo /etc/init.d/ssh start

sudo /etc/init.d/ssh start

This init.d is used to start other daemons. For example, if you have Apache, MySQL, Samba etc. You can also stop the service with stop or restart it with restart.

此init.d用于启动其他守护程序。 举例来说,如果你有阿帕奇MySQL的 ,桑巴等,还可以停止与停止服务或重新启动重新启动它。

在启动时启动 ( Have It Start at Bootup )

To set it up so the ssh server starts every time the Pi boots up, run this command once:

要对其进行设置,以便在Pi每次启动时都启动ssh服务器,请运行以下命令一次:

sudo update-rc.d ssh defaults

sudo update-rc.d ssh defaults

You can check that it worked by forcing your Pi to reboot with the reboot command:

您可以使用重新启动命令强制您的Pi重新启动,以检查其是否有效:

sudo reboot

sudo reboot

Then after rebooting try to connect to it using Putty or WinSCP (details below).

然后,重新启动后,尝试使用Putty或WinSCP连接到它(详细信息如下)。

关机并重新启动 ( Powering Down and Rebooting )

It's possible to corrupt your SD card with power offs before it halts. The result: reinstall everything. Only power down once you have fully shut down your Pi. Given its low power usage and little heat given off, you could probably leave it running 24x7.

暂停之前,可能会因关机而损坏SD卡。 结果:重新安装所有内容。 仅在完全关闭Pi后才关闭电源。 考虑到它的低功耗和散发的热量很少,您可能会使其保持24x7全天候运行。

If you want to shut it down, use the shutdown command:

如果要关闭它,请使用shutdown命令:

sudo shutdown -h now

sudo shutdown -h now

Change -h to -r and it does the same as sudo reboot.

将-h更改为-r,与sudo reboot相同。

Putty and WinSCP

腻子和WinSCP

If you're accessing your Pi from the command line of a Windows/Linux or Mac PC then use Putty or the commercial (but free for private use) Tunnelier. Both are great for general browsing around your Pi's folders and copying files to or from a Windows PC. Download them from these URLs:

如果要从Windows / Linux或Mac PC的命令行访问Pi,请使用Putty或商业版(但免费供私人使用)的Tunnelier。 两者都非常适合在Pi的文件夹中进行常规浏览以及将文件复制到Windows PC或从Windows PC复制文件。 从以下URL下载它们:

Your Pi needs to be connected to your network before you use Putty or WinSCP and you need to know its IP address. On my network, my Pi is on 192.168.1.69. You can find yours by typing in

在使用Putty或WinSCP之前,您的Pi必须已连接到网络,并且您需要知道其IP地址。 在我的网络上,我的Pi在192.168.1.69上。 您可以输入以下内容找到您的内容

/sbin/ifconfig

/sbin/ifconfig

and on the 2nd line of the output, you'll see inet addr: followed by your IP address.

在输出的第二行,您将看到inet addr:和IP地址。

For Putty, it's easiest to download putty.exe or the zip file of all the exes and put them in a folder. When you run putty it pops up a configuration Window. Enter your IP address in the input field where it says Host Name (or IP address) and enter pi or any name there.

对于Putty,最简单的方法是下载putty.exe或所有exe的zip文件并将其放在文件夹中。 当您运行腻子时,它会弹出一个配置窗口。 在显示主机名(或IP地址)的输入字段中输入IP地址,然后在其中输入pi或任何名称。

Now click the save button then the open button at the bottom. You'll have to login into your pi but now you can use it as if you were actually there.

现在,单击保存按钮,然后单击底部的打开按钮。 您将必须登录到pi,但是现在您可以像实际使用它一样使用它。

This can be quite useful, as it's far easier to cut and paste long text strings in via a putty terminal.

这非常有用,因为通过腻子终端剪切和粘贴长文本字符串要容易得多。

Try running this command:

尝试运行以下命令:

ps ax

ps ax

That shows a list of processes running on your pi. These include ssh (the two sshd) and Samba (nmbd and smbd) and many others.

这显示了在pi上运行的进程的列表。 其中包括ssh(两个sshd)和Samba(nmbd和smbd)等等。

PID TTY STAT TIME COMMAND858 ? Ss 0:00 /usr/sbin/sshd866 ? Ss 0:00 /usr/sbin/nmbd -D887 ? Ss 0:00 /usr/sbin/smbd -D1092 ? Ss 0:00 sshd: pi [priv]

PID TTY STAT TIME COMMAND858 ? Ss 0:00 /usr/sbin/sshd866 ? Ss 0:00 /usr/sbin/nmbd -D887 ? Ss 0:00 /usr/sbin/smbd -D1092 ? Ss 0:00 sshd: pi [priv]

WinSCP ( WinSCP )

We find it most useful to set it up in two screen mode rather than in explorer mode but it's easily changed in the Preferences. Also in preferences under Integration/Applications change the path to the putty.exe so you can easily jump into putty.

我们发现将其设置为两屏模式而不是资源管理器模式最有用,但是可以在“首选项”中轻松进行更改。 另外,在“集成/应用程序”下的首选项中,还可以更改putty.exe的路径,因此您可以轻松跳入putty。

When you connect to the pi, it starts at your home directory which is /home/pi. Click on the two .. to view the folder above and do it once more to get to the root. You can see all of the 20 Linux folders.

当您连接到pi时,它从您的主目录/ home / pi开始。 单击两个..以查看上方的文件夹,然后再次进行操作以获取根目录。 您可以看到所有20个Linux文件夹。

After you've used a terminal for a while you'll see a hidden file .bash_history (not that well hidden!). This is a text file of your command history with all the commands you've used before so copy it, edit out the stuff you don't want and keep the useful commands somewhere safe.

在使用终端一段时间后,您将看到一个隐藏文件.bash_history(隐藏得不那么好!)。 这是命令历史记录的文本文件,其中包含您之前使用过的所有命令,因此请将其复制,编辑出不需要的内容并将有用的命令保存在安全的地方。

翻译自: https://www.thoughtco.com/setup-use-ssh-with-raspberry-pi-958618

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值