element14 Community
element14 Community
    Register Log In
  • Site
  • Search
  • Log In Register
  • About Us
  • Community Hub
    Community Hub
    • What's New on element14
    • Feedback and Support
    • Benefits of Membership
    • Personal Blogs
    • Members Area
    • Achievement Levels
  • Learn
    Learn
    • Ask an Expert
    • eBooks
    • element14 presents
    • Learning Center
    • Tech Spotlight
    • STEM Academy
    • Webinars, Training and Events
    • Learning Groups
  • Technologies
    Technologies
    • 3D Printing
    • FPGA
    • Industrial Automation
    • Internet of Things
    • Power & Energy
    • Sensors
    • Technology Groups
  • Challenges & Projects
    Challenges & Projects
    • Design Challenges
    • element14 presents Projects
    • Project14
    • Arduino Projects
    • Raspberry Pi Projects
    • Project Groups
  • Products
    Products
    • Arduino
    • Avnet Boards Community
    • Dev Tools
    • Manufacturers
    • Multicomp Pro
    • Product Groups
    • Raspberry Pi
    • RoadTests & Reviews
  • Store
    Store
    • Visit Your Store
    • Choose another store...
      • Europe
      •  Austria (German)
      •  Belgium (Dutch, French)
      •  Bulgaria (Bulgarian)
      •  Czech Republic (Czech)
      •  Denmark (Danish)
      •  Estonia (Estonian)
      •  Finland (Finnish)
      •  France (French)
      •  Germany (German)
      •  Hungary (Hungarian)
      •  Ireland
      •  Israel
      •  Italy (Italian)
      •  Latvia (Latvian)
      •  
      •  Lithuania (Lithuanian)
      •  Netherlands (Dutch)
      •  Norway (Norwegian)
      •  Poland (Polish)
      •  Portugal (Portuguese)
      •  Romania (Romanian)
      •  Russia (Russian)
      •  Slovakia (Slovak)
      •  Slovenia (Slovenian)
      •  Spain (Spanish)
      •  Sweden (Swedish)
      •  Switzerland(German, French)
      •  Turkey (Turkish)
      •  United Kingdom
      • Asia Pacific
      •  Australia
      •  China
      •  Hong Kong
      •  India
      •  Korea (Korean)
      •  Malaysia
      •  New Zealand
      •  Philippines
      •  Singapore
      •  Taiwan
      •  Thailand (Thai)
      • Americas
      •  Brazil (Portuguese)
      •  Canada
      •  Mexico (Spanish)
      •  United States
      Can't find the country/region you're looking for? Visit our export site or find a local distributor.
  • Translate
  • Profile
  • Settings
Raspberry Pi
  • Products
  • More
Raspberry Pi
Blog Accessing and Controlling the Pi
  • Blog
  • Forum
  • Documents
  • Quiz
  • Events
  • Polls
  • Files
  • Members
  • Mentions
  • Sub-Groups
  • Tags
  • More
  • Cancel
  • New
Join Raspberry Pi to participate - click to join for free!
Featured Articles
Announcing Pi
Technical Specifications
Raspberry Pi FAQs
Win a Pi
GPIO Pinout
Raspberry Pi Wishlist
Comparison Chart
Quiz
  • Share
  • More
  • Cancel
Group Actions
  • Group RSS
  • More
  • Cancel
Engagement
  • Author Author: shabaz
  • Date Created: 7 Jul 2017 2:20 PM Date Created
  • Views 3948 views
  • Likes 17 likes
  • Comments 12 comments
Related
Recommended
  • coding
  • rpibeginner
  • get started with pi
  • rpi
  • sudo_open
  • raspberry_pi_getting_started

Accessing and Controlling the Pi

shabaz
shabaz
7 Jul 2017

  • Introduction
  • Using the Shell (Command Prompt or Terminal)
  • Simplifying access to the Pi with SSH
  • Transferring Files with PuTTY
  • Securing the Pi
  • Enabling the root user account (Superuser)
  • Remote Desktop (Accessing your Pi from a PC)
  • Using a Serial Console
  • Navigating in the Shell (command prompt)
  • Next Steps

 

Introduction

This blog post has a collection of steps or ‘things’ that can be done with the Pi in order to be able to access it flexibly.

These steps allow you to work with the Pi either using a keyboard/mouse/TV or using your desktop PC or laptop and remotely connecting to the Pi.

 

The key steps are listed and all the links to click on for more information on topics. Not everything here is essential; it is more a la carte so you can pick and choose.

 

Use this blog post as a quick reference to do these ‘things’:

 

  • Using the shell (command prompt)
  • Simplifying access to the Pi with SSH
  • Transferring Files
  • Securing the Pi
  • Enabling the root user (superuser)
  • Remote desktop (accessing the graphical display from a PC)
  • Enabling the Serial Console connection
  • Navigating in the Shell (Command Prompt)

 

Note: If you're completely starting from scratch, then you can configure and install a fresh micro SD card with the latest appropriate image on it, by following the information here: Before You Start Coding the Pi and then come back here!

 

Using the Shell (Command Prompt or Terminal)

When a PC runs Windows it isn’t just running an operating system, it is also running a graphical user interface. Daily interaction with the PC is through the graphical user interface but users can bring up a command prompt in Windows and just type instructions. A similar thing is possible with the Pi. The operating system happens to be Linux, and the graphical user interface is called PIXEL. The entire thing can be called Raspbian which is the name of the combined distribution of Linux, PIXEL and any other stuff bundled by the creators of the Raspbian release.

 

The shell can also be loosely referred to as a command prompt or a terminal window; they all mean the same thing. It can be invoked from the Pi’s desktop as shown here.

image

 

Simplifying access to the Pi with SSH

If you’re not able to get access to the TV always and wish to use your Pi from your PC, then something called SSH is very handy. It allows you to write and edit your code on a PC, and then transfer the code across to the Pi and run it remotely. To use this, first follow the steps to enable SSH capability.

 

You'll also need to know the IP address of the Pi. There are two easy ways:

 

  1. If you only have one Pi connected to your home network, then try going to a Windows command prompt (or a Linux or Mac terminal) and typing ping raspberrypi because often that will reveal it.
  2. Alternatively, navigate to your home router using a web browser and check within the pages there. The address of the home router is usually http://192.168.0.254 or http://192.168.1.254

 

Here's an example using the first method:

image

 

Next, ‘SSH client’ software is needed. The free option for Windows is called PuTTYhttp://www.putty.org/and it works well (for Mac and Linux PCs, SSH client software is built-in, it is accessed from the Mac/Linux command prompt by literally typing ssh). After PuTTY is installed, type in the IP address of the Pi (obtainable as described above) and type a name for your Pi and click Save.

image

 

From now on you can access the Pi by double-clicking the name, and it will bring up a window where it will prompt for the username/password (pi/raspberry by default).

image

 

The screenshots further below happen to use software called SecureCRT merely because I’m more familiar with it, but the same result can be achieved using PuTTY. I’ve customized my display so that the Pi appears in a blue screen. You can do similar things with PuTTY.

 

Transferring Files with PuTTY

Transferring files from the PC to the Pi, or vice versa, is possible with PuTTY too. It is achieved using the command line on your PC. For Windows, click on the start prompt and type cmd to bring this up.

 

For this example, a file called example.txt will be transferred from the PC to the Pi user’s default home folder or directory which is at /home/pi

 

C:\Users\bob>cd ..
C:\Users>cd ..
C:\>cd "Program Files"
C:\Program Files>cd PuTTY
C:\Program Files\PuTTY>pscp.exe c:\myprojects\example.txt pi@192.168.1.179:/home/pi
pi@192.168.1.179's password:
example.txt                    | 0 kB |   0.8 kB/s | ETA: 00:00:00 | 100%

 

It is fairly similar to pull files from the Pi to the PC. Here a file called example2.txt in the pi user’s home folder is transferred to the PC:

 

C:\Program Files\PuTTY>pscp.exe pi@192.168.1.179:/home/pi/example2.txt c:\c_root\install
pi@192.168.1.179's password:
example2.txt                        | 0 kB |   0.0 kB/s | ETA: 00:00:00 | 100%

 

There are other programs which achieve the same thing with a graphical user interface and they could be easier to use. PuTTY is a basic free option for Windows. For Mac and Linux users, a different software option is already built-in; from a Mac/Linux command prompt the program is called sftp (type man sftp for detailed instructions).

 

Securing the Pi

The steps here are quite important! Once Raspbian is up-and-running, it is advisable to change the password for the default ‘pi’ user. To do this, get to a command prompt and type passwd and it will prompt for the old password (raspberry by default) and then the new password. Simple passwords won’t be accepted.

 

Enabling the root user account (Superuser)

Some things are privileged and cannot be accessed by someone who has logged in as the ‘pi’ user. However, sometimes it is necessary to perform a privileged task. One method is to type sudo before entering the command for the privileged task.

 

Another method that some would find more preferable is to enable the root user account. It is easy to do using the sudo -i command. As pi user, do the following:

image

 

Now you have a Pi which you can log into as the pi user, or as the root user.

 

Remote Desktop (Accessing your Pi from a PC)

When the Pi is connected to a network there are many ways to connect to it. One method, SSH, has already been discussed. It provides a command line interface and the ability to transfer files to/from it. Occasionally the graphical capabilities of the Pi may be needed, and for that a TV can be plugged in using the HDMI connection. However, it is also possible to use the network to display the Pi’s desktop and any graphics on a PC. There are several ways to do this. One method called Windows Remote Desktop is described here. Another method is called VNC and there are online resources on it.

 

To enable the Pi to be able to send graphical display information, software called xrdp needs to be installed as shown here:

image

 

Next, go to the Windows start bar and type remote desktop and it should find the application. Click on it.

image

 

Type the IP address of the Pi and click on Connect. A large blank window will appear, and a prompt for the username/password for accessing the Pi.

image

 

Once the details are filled it, the usual Pi desktop will appear on the PC.

image

 

If you’re not using a Windows PC and are instead using a Mac or Linux PC then software needs to be installed (Windows already has the correct software installed). For a Mac, install Remote Desktop Client from the itunes store,  and for Linux PCs install rdesktop.

 

Using a Serial Console

If you look around the back of most computers and computer-based products in business and industry, you’ll see a port marked ‘Console’. It offers a last-resort method of connection if more sophisticated methods like keyboard/mouse, wireless and Ethernet fail. The console on such computers can be connected to a PC using an RS232 serial cable, or can be connected to an old-school dial-up modem if the computer is at a remote site and no-one can get to it in any other way. The Pi does have a console connection, but it needs an adapter before it can be attached to a computer. It is known as a USB-to-UART adapter and it converts from a PC USB connection to a three-wire connection where one wire is ground, and the other two wires send data to/from the Pi using digital values of 3.3V and 0V to represent 1’s and 0’s, and groupings of these representing ASCII characters. The end result is a text-based connection much like with SSH, but using a relatively simple communication method compared to SSH over the network. When all else fails often the serial console connection continues to run and provides entry into the computer to examine the cause for failure of the other connection methods for example.

 

There are many suitable USB-to-UART adapters, but they come in different voltage versions. A 3.3V compatible adapter is required which most are (some older ones might only support 5V which will damage the Pi’s serial interface).

 

A suitable flying lead USB-to-UART adapter (the functionality is embedded within the USB connector housing) is TTL-232RG-VIP-WETTL-232RG-VIP-WE and it has six wires. Only four need to be connected (two are 3.3V power and ground, and the other two are the transmit/receive wires for the digital data). You could even make your own USB-UART adapter on stripboard. The photo below shows a home-made one on a printed circuit board (PCB).

image

 

Setting up the console has a few implications due to some discrepancies between the Pi 3 and earlier Pi releases that won’t be discussed here, and a power user will probably want to read up to understand them. Anyway, to enable the serial interface on the Pi for now, as root user, go to the /boot folder and append the following at the end of the config.txt file:

 

# initialize the uart (mini-uart on pi 3, PL011 on earlier pi's)
enable_uart=1

 

As an optional (but recommended) thing, in the same folder (still as root user) edit the cmdline.txt file and remove the text quiet there. By removing this text, the serial console will provide lots of useful debugging information when it starts up. The Pi must be rebooted for the changes to take effect. Still as root user, type reboot to do this.

 

On the PC, ‘serial terminal software’ is needed. On Windows PCs PuTTY can be used for this. Go to the Start button and then type device manager and click on it. Scroll down and expand the ‘Ports’ section. Plug the USB UART adapter in and you’ll see a new port appear. The name of the port (COM16 in the screenshot below) will need to be noted, and then in PuTTY select the ‘Serial’ connection type instead of the usual SSH, and type in a speed of 11500 and enter the name of the port to match the COM name from the device manager window. The settings can be saved and then the saved session can be started at any time by double-clicking on it.

image

 

When the session is run a blank window appear, press Enter and you should see the Pi’s usual login prompt. As mentioned earlier if the Pi is now rebooted then upon startup a whole load of information will appear.

image

 

Navigating in the Shell (command prompt)

The command prompt used so far actually has a formal name; it is called the bash shell. Other command prompts are possible too. The bash shell happens to be one of the most popular ones. There are things that are worth learning because it will speed up working in the command prompt.

 

One obvious thing that you may have already noticed is tab completion; if a command or folder name or file name is partially typed, pressing the tab button will auto-complete.

 

Another thing that is less obvious but is highly useful is that when typing in a long line, if you make a mistake and you need to quickly move to the beginning of the line, you don’t need to hold down the left-arrow to move the cursor one character at a time. You can just press Ctrl-A. To move back to the end of the line, press Ctrl-E.

 

If you’ve typed a long line but realized you don’t need it, instead of holding down the backspace key and deleting character-by-character, you can just press Ctrl-C. The text will stay on the screen but the line will be aborted and will not be actioned by the bash shell.

 

To repeat a command (or to recall it or edit it before executing the command again) press the up-arrow. You can navigate a chunk of historical commands by using the up/down arrow keys.

 

Another useful thing is to type notes or comments in the command line; these are useful when logging the entire session (this is an option in PuTTY for example) and you want to intersperse some notes to yourself in the logged file. To insert a note, just start the line with a hash (#) character.

Another really nice feature requires a bit of configuration. Edit the .bashrc file that is in your home folder (/home/pi). The file is normally hidden from view because the filename begins with a dot. At the end of the file place the text stty stop '' (that's not a double-quote, it is two single quotes) and then save the file. Now whenever a new command prompt is created, a history searching capability is enabled. If you know you’ve typed a command before with (say) the characters gcc in it, type Ctrl-R and then type gcc. The bash shell will automatically display the entire line that contained that text. If you’re fine with it, press the right arrow to edit the line and press enter to execute it. If you want to abort, press Ctrl-C. If the line found isn’t the one you need, press Ctrl-R again and it will continue to search the next occurrence in the command history. If you reach the end of the history and want to search in the other direction, use Ctrl-S.

 

Sometimes the simplest methods are the best, and another popular method is to just have a text editor open and copy-and-paste your important commands into there for future reference.

 

Here is a summary of the tasks and shortcuts:

 

 

TaskShortcut
Auto-completePress Tab
Move cursor to beginning or the end of a linePress Ctrl-A or Ctrl-E
Abort a linePress Ctrl-C
Repeat commands from the historyUse the cursor keys. Press the up-arrow repeatedly until you find what you need
Type notes or commentsStart the line with a hash (#) character
Search for commands from the historyPress Ctrl-R and then type the search term. Press Ctrl-R again to continue the search. Press Ctrl-S to search in the other direction (see the text earlier how to enable this feature). Once you’ve found your command line, press the right arrow to edit it or press Enter to execute it

 

Next Steps

Proceed to Working with the Pi: Getting Online, I/O and Command Lines

  • Sign in to reply

Top Comments

  • DAB
    DAB over 8 years ago +2
    Nice post. Setting up a remotely accessed RPi is another thing on my todo list. Thanks DAB
  • vigneshaithal
    vigneshaithal over 7 years ago +2
    Very Useful, Thank you:)
  • bmag
    bmag over 7 years ago +2
    just what i needed thank you.
  • shabaz
    shabaz over 5 years ago in reply to gam3t3ch

    Hi Wesley,

     

    Thanks! Also, that's very cool that you ran a course using remote viewers. I've seen that done with some labs at workplaces too (they were using just VNC since attendees were all in a classroom), and it did simplify things for the trainer.

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • More
    • Cancel
  • gam3t3ch
    gam3t3ch over 5 years ago

    Awesome information! always love reading your posts.

     

    My most common with multiple raspberry pi's on a network is to use through vnc viewer but when I ran my raspberry pi course I had them all connect to their raspberry pi's at my home with teamviewer this way they would have their own separate accounts and I was able to still connect locally to their pi's if needed.  both you can use file transfer as well.

     

    https://www.teamviewer.com/en/download/linux/

    Then scroll to teamviewer host and grab the armv7 debian, ubuntu, raspbian file and then extract it and mv to your opt folder and then should be able to run and install it from there and then just sign in to your account on it.  Then on any device you have teamviewer you can remote into it.

     

    vnc viewer is just go to start (pi icon) preferences-raspberry pi configuration-interfaces- then enable vnc.

    By signing in this will allow you access via other networks to your pi as well.

     

    if doing anything graphically teamviewer will display more things video/games over vnc which will black out games and video.

    • Cancel
    • Vote Up +1 Vote Down
    • Sign in to reply
    • More
    • Cancel
  • shabaz
    shabaz over 5 years ago in reply to sannerwind

    Hi Jay,

    sannerwind  wrote:

     

    1) How do you run   say a python program in the PI, under an IDE, executing the IDE commands from the PC? 

    To do that, personally I'd use the 'Simplifying access to the Pi with SSH' method to get a command line view of the Pi on the PC, and then use a text editor running on the PC. Today, for that editor I'd probably use Microsoft Visual Code, because it is expandable, free to use, has syntax highlighting for Python, and you can directly access the code files on the Pi with it, so the single app will allow you to do it all. To get the command line view of the Pi, PuTTY is great (I use SecureCRT, but that is a pay option - PuTTY works well too).

    You can see some of the capabilities of Visual Code below. I have a free SFTP extension installed, and it automatically creates a sftp.json file in which I enter my Pi's IP address and login username and the folder name where I want to run the apps. I create the Python code on the PC, and then right-click on it to select Upload. Then, using PuTTY or SecureCRT (blue window) I can run the code directly on the Pi. Incidentally you can also run code directly on the PC too (useful to test some things, won't work with everything since the PC does not have GPIO like the Pi), that is shown at the bottom of the screenshot in the Visual Code window.

    image

     

    For your second question, if you connect the Pi to a TV/monitor and mouse and keyboard, but still want to occasionally back-up content from the Pi to the PC, there are many ways to do that. Personally I just zip up content and then transfer using SFTP (SecureCRT has this built-in, otherwise the Visual Code 'Download' capability could be used, or see the 'Transferring files with PuTTY' section. All of these options work for most small hobby projects. For a larger project, you'd want to use a different system (known as version control, or alternatively Github could be used).

    • Cancel
    • Vote Up +1 Vote Down
    • Sign in to reply
    • More
    • Cancel
  • colporteur
    colporteur over 5 years ago

    Most of my Pi work is headless therefore ssh is my default. Since I don't use MS Windows I never have to deal with the client setup. A Pi build for me always includes dropping a blank file called ssh into the /boot directory after imaging a SD card.

     

    As usual from you, an excellent compilation of resources. I'm going to bookmark it and share it with my students.

    • Cancel
    • Vote Up +1 Vote Down
    • Sign in to reply
    • More
    • Cancel
  • sannerwind
    sannerwind over 5 years ago

    Great article. 1) How do you run   say a python program in the PI, under an IDE, executing the IDE commands from the PC?  Can you load both the Python and its IDE into the PI. Without an IDE programming is very difficult. 2) Is there an easy way to set up a PI with Python, IDE, a mouse and keyboard, Big screen (At least say 20 inches)? But some backup that can permit the PC-RPI data transfers?  Thanks in advance Jay Rosenberg, Sannerwind@gmail.com

    • Cancel
    • Vote Up +1 Vote Down
    • Sign in to reply
    • More
    • Cancel
>
element14 Community

element14 is the first online community specifically for engineers. Connect with your peers and get expert answers to your questions.

  • Members
  • Learn
  • Technologies
  • Challenges & Projects
  • Products
  • Store
  • About Us
  • Feedback & Support
  • FAQs
  • Terms of Use
  • Privacy Policy
  • Legal and Copyright Notices
  • Sitemap
  • Cookies

An Avnet Company © 2025 Premier Farnell Limited. All Rights Reserved.

Premier Farnell Ltd, registered in England and Wales (no 00876412), registered office: Farnell House, Forge Lane, Leeds LS12 2NE.

ICP 备案号 10220084.

Follow element14

  • X
  • Facebook
  • linkedin
  • YouTube